Skip to content

Commit ef24c21

Browse files
committed
fix(oauth): GetAccessToken returns *oauth2.Token rather than a token source.
1 parent 40a226b commit ef24c21

File tree

2 files changed

+9
-23
lines changed

2 files changed

+9
-23
lines changed

auth_providers/auth_oauth.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ func (b *CommandConfigOauth) GetServerConfig() *Server {
441441
}
442442

443443
// GetAccessToken returns the OAuth2 token source for the given configuration.
444-
func (b *CommandConfigOauth) GetAccessToken() (oauth2.TokenSource, error) {
444+
func (b *CommandConfigOauth) GetAccessToken() (*oauth2.Token, error) {
445445
if b == nil {
446446
return nil, fmt.Errorf("CommandConfigOauth is nil")
447447
}
@@ -450,13 +450,11 @@ func (b *CommandConfigOauth) GetAccessToken() (oauth2.TokenSource, error) {
450450

451451
if b.AccessToken != "" && (b.ClientID == "" || b.ClientSecret == "" || b.TokenURL == "") {
452452
log.Printf("[DEBUG] Access token is explicitly set, and no client credentials are provided. Using static token source.")
453-
return oauth2.StaticTokenSource(
454-
&oauth2.Token{
455-
AccessToken: b.AccessToken,
456-
TokenType: DefaultTokenPrefix,
457-
Expiry: b.Expiry,
458-
},
459-
), nil
453+
return &oauth2.Token{
454+
AccessToken: b.AccessToken,
455+
TokenType: DefaultTokenPrefix,
456+
Expiry: b.Expiry,
457+
}, nil
460458
}
461459

462460
log.Printf("[DEBUG] Getting OAuth2 token source for client ID: %s", b.ClientID)
@@ -492,7 +490,7 @@ func (b *CommandConfigOauth) GetAccessToken() (oauth2.TokenSource, error) {
492490
return nil, fmt.Errorf("received empty OAuth token for client ID: %s", b.ClientID)
493491
}
494492

495-
return tokenSource, nil
493+
return token, nil
496494
}
497495

498496
// RoundTrip executes a single HTTP transaction, adding the OAuth2 token to the request

auth_providers/auth_oauth_test.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"testing"
2727

2828
"github.com/Keyfactor/keyfactor-auth-client-go/auth_providers"
29-
"golang.org/x/oauth2"
3029
)
3130

3231
func TestOAuthAuthenticator_GetHttpClient(t *testing.T) {
@@ -397,19 +396,8 @@ func authOauthTest(
397396
t.FailNow()
398397
return
399398
}
400-
if oauthToken == nil {
401-
t.Errorf("oAuth auth test '%s' failed to get token source", testName)
402-
t.FailNow()
403-
return
404-
}
405-
var at *oauth2.Token
406-
var tkErr error
407-
at, tkErr = oauthToken.Token()
408-
if tkErr != nil {
409-
t.Errorf("oAuth auth test '%s' failed to get token source", testName)
410-
t.FailNow()
411-
}
412-
if at == nil || at.AccessToken == "" {
399+
400+
if oauthToken == nil || oauthToken.AccessToken == "" {
413401
t.Errorf("oAuth auth test '%s' failed to get token source", testName)
414402
t.FailNow()
415403
return

0 commit comments

Comments
 (0)