Skip to content

Commit 76cefcc

Browse files
committed
fix(manager): requestTimeout and parser
Set default requestTimeout to 30 seconds
1 parent aba78bf commit 76cefcc

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

manager/defaults.go

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
)
1414

1515
const (
16+
DefaultRequestTimeout = 30 * time.Second
1617
DefaultExpirationRefreshRatio = 0.7
1718
DefaultRetryOptionsMaxAttempts = 3
1819
DefaultRetryOptionsBackoffMultiplier = 2.0
@@ -85,6 +86,9 @@ func defaultTokenManagerOptionsOr(options TokenManagerOptions) TokenManagerOptio
8586
if options.ExpirationRefreshRatio == 0 {
8687
options.ExpirationRefreshRatio = DefaultExpirationRefreshRatio
8788
}
89+
if options.RequestTimeout == 0 {
90+
options.RequestTimeout = DefaultRequestTimeout
91+
}
8892
return options
8993
}
9094

@@ -108,16 +112,31 @@ func (*defaultIdentityProviderResponseParser) ParseResponse(response shared.Iden
108112
if err != nil {
109113
return nil, fmt.Errorf("failed to get auth result: %w", err)
110114
}
111-
if authResult.ExpiresOn.IsZero() {
112-
return nil, fmt.Errorf("auth result expiration time is not set")
115+
116+
claims := struct {
117+
jwt.RegisteredClaims
118+
Oid string `json:"oid,omitempty"`
119+
}{}
120+
121+
// Parse the token to extract claims, but note that signature verification
122+
// should be handled by the identity provider
123+
_, _, err = jwt.NewParser().ParseUnverified(authResult.AccessToken, &claims)
124+
if err != nil {
125+
return nil, fmt.Errorf("failed to parse JWT token: %w", err)
113126
}
114-
if authResult.IDToken.Oid == "" {
127+
128+
if claims.Oid == "" {
115129
return nil, fmt.Errorf("auth result OID is empty")
116130
}
117-
rawToken = authResult.IDToken.RawToken
118-
username = authResult.IDToken.Oid
131+
132+
if claims.ExpiresAt.IsZero() {
133+
return nil, fmt.Errorf("auth result expiration time is not set")
134+
}
135+
136+
rawToken = authResult.AccessToken
137+
username = claims.Oid
119138
password = rawToken
120-
expiresOn = authResult.ExpiresOn.UTC()
139+
expiresOn = claims.ExpiresAt.UTC()
121140

122141
case shared.ResponseTypeRawToken, shared.ResponseTypeAccessToken:
123142
var tokenStr string

manager/token_manager.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ type TokenManagerOptions struct {
4444
RetryOptions RetryOptions
4545

4646
// RequestTimeout is the timeout for the request to the identity provider.
47+
//
48+
// default: 30 seconds
4749
RequestTimeout time.Duration
4850
}
4951

0 commit comments

Comments
 (0)