Skip to content

Commit

Permalink
fix: Issue #1008 : Use exchange info's TLS Configuration for cert bas…
Browse files Browse the repository at this point in the history
…ed auth (#1043)

Fix for #1008
  • Loading branch information
ttschampel authored Jun 27, 2024
1 parent b1931e4 commit 93d8f70
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions sdk/idp_cert_exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ func NewCertExchangeTokenSource(info oauth.CertExchangeInfo, credentials oauth.C
return &exchangeSource, nil
}

func (c *CertExchangeTokenSource) AccessToken(ctx context.Context, client *http.Client) (auth.AccessToken, error) {
func (c *CertExchangeTokenSource) AccessToken(ctx context.Context, _ *http.Client) (auth.AccessToken, error) {
c.tokenMutex.Lock()
defer c.tokenMutex.Unlock()

if c.token == nil || c.token.Expired() {
tok, err := oauth.DoCertExchange(ctx, client, c.IdpEndpoint, c.info, c.credentials, c.key)
tok, err := oauth.DoCertExchange(ctx, c.IdpEndpoint, c.info, c.credentials, c.key)
if err != nil {
return "", err
}
Expand Down
8 changes: 7 additions & 1 deletion sdk/internal/oauth/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,17 @@ func getTokenExchangeRequest(ctx context.Context, tokenEndpoint, dpopNonce strin
return req, nil
}

func DoCertExchange(ctx context.Context, client *http.Client, tokenEndpoint string, exchangeInfo CertExchangeInfo, clientCredentials ClientCredentials, key jwk.Key) (*Token, error) {
func DoCertExchange(ctx context.Context, tokenEndpoint string, exchangeInfo CertExchangeInfo, clientCredentials ClientCredentials, key jwk.Key) (*Token, error) {
req, err := getCertExchangeRequest(ctx, tokenEndpoint, clientCredentials, exchangeInfo, key)
if err != nil {
return nil, err
}
client := &http.Client{
Transport: &http.Transport{
TLSClientConfig: exchangeInfo.TLSConfig,
},
}

resp, err := client.Do(req)
if err != nil {
return nil, fmt.Errorf("error making request to IdP for certificate exchange: %w", err)
Expand Down
5 changes: 0 additions & 5 deletions sdk/internal/oauth/oauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,6 @@ func (s *OAuthSuite) TestCertExchangeFromKeycloak() {

tok, err := DoCertExchange(
context.Background(),
&http.Client{
Transport: &http.Transport{
TLSClientConfig: &tlsConfig,
},
},
s.keycloakHTTPSEndpoint,
exhcangeInfo,
clientCredentials,
Expand Down

0 comments on commit 93d8f70

Please sign in to comment.