@@ -242,14 +242,14 @@ func (c *Config) Client(ctx context.Context, t *Token) *http.Client {
242242 return NewClient (ctx , c .TokenSource (ctx , t ))
243243}
244244
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,
247246//
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 {
250249 tkr := & tokenRefresher {
251250 ctx : ctx ,
252251 conf : c ,
252+ opts : opts ,
253253 }
254254 if t != nil {
255255 tkr .refreshToken = t .RefreshToken
@@ -260,12 +260,21 @@ func (c *Config) TokenSource(ctx context.Context, t *Token) TokenSource {
260260 }
261261}
262262
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+
263271// tokenRefresher is a TokenSource that makes "grant_type=refresh_token"
264272// HTTP requests to renew a token using a RefreshToken.
265273type tokenRefresher struct {
266274 ctx context.Context // used to get HTTP requests
267275 conf * Config
268276 refreshToken string
277+ opts []AuthCodeOption
269278}
270279
271280// WARNING: Token is not safe for concurrent access, as it
@@ -277,10 +286,15 @@ func (tf *tokenRefresher) Token() (*Token, error) {
277286 return nil , errors .New ("oauth2: token expired and refresh token is not set" )
278287 }
279288
280- tk , err := retrieveToken ( tf . ctx , tf . conf , url.Values {
289+ v := url.Values {
281290 "grant_type" : {"refresh_token" },
282291 "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 )
284298
285299 if err != nil {
286300 return nil , err
0 commit comments