Skip to content

Commit e42be94

Browse files
committed
oauth: Fix regression with possibly nil http.Client
1 parent da0f385 commit e42be94

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

sdk/auth/oauth/oauth.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/lestrrat-go/jwx/v2/jwk"
1717
"github.com/lestrrat-go/jwx/v2/jws"
1818
"github.com/lestrrat-go/jwx/v2/jwt"
19+
"github.com/opentdf/platform/sdk/httputil"
1920
)
2021

2122
const (
@@ -145,6 +146,9 @@ func GetAccessToken(client *http.Client, tokenEndpoint string, scopes []string,
145146
if err != nil {
146147
return nil, err
147148
}
149+
if client == nil {
150+
client = httputil.SafeHTTPClient()
151+
}
148152

149153
resp, err := client.Do(req)
150154
if err != nil {
@@ -248,6 +252,9 @@ func DoTokenExchange(ctx context.Context, client *http.Client, tokenEndpoint str
248252
if err != nil {
249253
return nil, err
250254
}
255+
if client == nil {
256+
client = httputil.SafeHTTPClient()
257+
}
251258
resp, err := client.Do(req)
252259
if err != nil {
253260
return nil, fmt.Errorf("error making request to IdP for token exchange: %w", err)
@@ -313,7 +320,11 @@ func DoCertExchange(ctx context.Context, tokenEndpoint string, exchangeInfo Cert
313320
return nil, err
314321
}
315322

316-
resp, err := exchangeInfo.HTTPClient.Do(req)
323+
client := exchangeInfo.HTTPClient
324+
if client == nil {
325+
client = httputil.SafeHTTPClient()
326+
}
327+
resp, err := client.Do(req)
317328
if err != nil {
318329
return nil, fmt.Errorf("error making request to IdP for certificate exchange: %w", err)
319330
}

0 commit comments

Comments
 (0)