Skip to content

Commit

Permalink
Support configuring the http client for token exchange requests
Browse files Browse the repository at this point in the history
  • Loading branch information
welteki committed May 30, 2024
1 parent a396dad commit 07d4780
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import (
// using the token exchange grant type.
// tokenURL should be the OpenFaaS token endpoint within the internal OIDC service
func ExchangeIDToken(tokenURL, rawIDToken string, options ...ExchangeOption) (*Token, error) {
c := &ExchangeConfig{}
c := &ExchangeConfig{
Client: http.DefaultClient,
}

for _, option := range options {
option(c)
Expand Down Expand Up @@ -51,7 +53,7 @@ func ExchangeIDToken(tokenURL, rawIDToken string, options ...ExchangeOption) (*T
fmt.Println(dump)
}

res, err := http.DefaultClient.Do(req)
res, err := c.Client.Do(req)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -91,6 +93,7 @@ func ExchangeIDToken(tokenURL, rawIDToken string, options ...ExchangeOption) (*T
type ExchangeConfig struct {
Audience []string
Scope []string
Client *http.Client
}

// ExchangeOption is used to implement functional-style options that modify the
Expand All @@ -112,3 +115,11 @@ func WithScope(scope []string) ExchangeOption {
c.Scope = scope
}
}

// WithHttpClient is an option to configure the http client
// used to make the token exchange request.
func WithHttpClient(client *http.Client) ExchangeOption {
return func(c *ExchangeConfig) {
c.Client = client
}
}

0 comments on commit 07d4780

Please sign in to comment.