@@ -36,9 +36,9 @@ type OAuthConfig struct {
36
36
// TokenStore is an interface for storing and retrieving OAuth tokens
37
37
type TokenStore interface {
38
38
// GetToken returns the current token
39
- GetToken () (* Token , error )
39
+ GetToken (ctx context. Context ) (* Token , error )
40
40
// SaveToken saves a token
41
- SaveToken (token * Token ) error
41
+ SaveToken (ctx context. Context , token * Token ) error
42
42
}
43
43
44
44
// Token represents an OAuth token
@@ -77,7 +77,7 @@ func NewMemoryTokenStore() *MemoryTokenStore {
77
77
}
78
78
79
79
// GetToken returns the current token
80
- func (s * MemoryTokenStore ) GetToken () (* Token , error ) {
80
+ func (s * MemoryTokenStore ) GetToken (ctx context. Context ) (* Token , error ) {
81
81
s .mu .RLock ()
82
82
defer s .mu .RUnlock ()
83
83
if s .token == nil {
@@ -87,7 +87,7 @@ func (s *MemoryTokenStore) GetToken() (*Token, error) {
87
87
}
88
88
89
89
// SaveToken saves a token
90
- func (s * MemoryTokenStore ) SaveToken (token * Token ) error {
90
+ func (s * MemoryTokenStore ) SaveToken (ctx context. Context , token * Token ) error {
91
91
s .mu .Lock ()
92
92
defer s .mu .Unlock ()
93
93
s .token = token
@@ -150,7 +150,7 @@ func (h *OAuthHandler) GetAuthorizationHeader(ctx context.Context) (string, erro
150
150
151
151
// getValidToken returns a valid token, refreshing if necessary
152
152
func (h * OAuthHandler ) getValidToken (ctx context.Context ) (* Token , error ) {
153
- token , err := h .config .TokenStore .GetToken ()
153
+ token , err := h .config .TokenStore .GetToken (ctx )
154
154
if err == nil && ! token .IsExpired () && token .AccessToken != "" {
155
155
return token , nil
156
156
}
@@ -218,13 +218,13 @@ func (h *OAuthHandler) refreshToken(ctx context.Context, refreshToken string) (*
218
218
}
219
219
220
220
// If no new refresh token is provided, keep the old one
221
- oldToken , _ := h .config .TokenStore .GetToken ()
221
+ oldToken , _ := h .config .TokenStore .GetToken (ctx )
222
222
if tokenResp .RefreshToken == "" && oldToken != nil {
223
223
tokenResp .RefreshToken = oldToken .RefreshToken
224
224
}
225
225
226
226
// Save the token
227
- if err := h .config .TokenStore .SaveToken (& tokenResp ); err != nil {
227
+ if err := h .config .TokenStore .SaveToken (ctx , & tokenResp ); err != nil {
228
228
return nil , fmt .Errorf ("failed to save token: %w" , err )
229
229
}
230
230
@@ -637,7 +637,7 @@ func (h *OAuthHandler) ProcessAuthorizationResponse(ctx context.Context, code, s
637
637
}
638
638
639
639
// Save the token
640
- if err := h .config .TokenStore .SaveToken (& tokenResp ); err != nil {
640
+ if err := h .config .TokenStore .SaveToken (ctx , & tokenResp ); err != nil {
641
641
return fmt .Errorf ("failed to save token: %w" , err )
642
642
}
643
643
0 commit comments