@@ -242,14 +242,14 @@ func (c *Config) Client(ctx context.Context, t *Token) *http.Client {
242
242
return NewClient (ctx , c .TokenSource (ctx , t ))
243
243
}
244
244
245
- // TokenSource returns a [TokenSource] that returns t until t expires,
246
- // automatically refreshing it as necessary using the provided context.
245
+ // TokenSourceWithOptions returns a [TokenSource] that returns t until t expires,
247
246
//
248
- // Most users will use [Config.Client] instead .
249
- func (c * Config ) TokenSource (ctx context.Context , t * Token ) TokenSource {
247
+ // This method provides a way to pass options to the token source .
248
+ func (c * Config ) TokenSourceWithOptions (ctx context.Context , t * Token , opts ... AuthCodeOption ) TokenSource {
250
249
tkr := & tokenRefresher {
251
250
ctx : ctx ,
252
251
conf : c ,
252
+ opts : opts ,
253
253
}
254
254
if t != nil {
255
255
tkr .refreshToken = t .RefreshToken
@@ -260,12 +260,21 @@ func (c *Config) TokenSource(ctx context.Context, t *Token) TokenSource {
260
260
}
261
261
}
262
262
263
+ // TokenSource returns a [TokenSource] that returns t until t expires,
264
+ // automatically refreshing it as necessary using the provided context.
265
+ //
266
+ // Most users will use [Config.Client] instead.
267
+ func (c * Config ) TokenSource (ctx context.Context , t * Token ) TokenSource {
268
+ return c .TokenSourceWithOptions (ctx , t )
269
+ }
270
+
263
271
// tokenRefresher is a TokenSource that makes "grant_type=refresh_token"
264
272
// HTTP requests to renew a token using a RefreshToken.
265
273
type tokenRefresher struct {
266
274
ctx context.Context // used to get HTTP requests
267
275
conf * Config
268
276
refreshToken string
277
+ opts []AuthCodeOption
269
278
}
270
279
271
280
// WARNING: Token is not safe for concurrent access, as it
@@ -277,10 +286,15 @@ func (tf *tokenRefresher) Token() (*Token, error) {
277
286
return nil , errors .New ("oauth2: token expired and refresh token is not set" )
278
287
}
279
288
280
- tk , err := retrieveToken ( tf . ctx , tf . conf , url.Values {
289
+ v := url.Values {
281
290
"grant_type" : {"refresh_token" },
282
291
"refresh_token" : {tf .refreshToken },
283
- })
292
+ }
293
+ for _ , opt := range tf .opts {
294
+ opt .setValue (v )
295
+ }
296
+
297
+ tk , err := retrieveToken (tf .ctx , tf .conf , v )
284
298
285
299
if err != nil {
286
300
return nil , err
0 commit comments