From 7bc4a859ea743e74d3a92a7cc7dc724f5f2826ed Mon Sep 17 00:00:00 2001 From: Sabith KS Date: Fri, 14 Jun 2024 19:16:41 -0700 Subject: [PATCH] Support for rfc 7523 in refresh token --- oauth2.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/oauth2.go b/oauth2.go index 09f6a49b8..795ddf9e7 100644 --- a/oauth2.go +++ b/oauth2.go @@ -246,10 +246,11 @@ func (c *Config) Client(ctx context.Context, t *Token) *http.Client { // automatically refreshing it as necessary using the provided context. // // Most users will use Config.Client instead. -func (c *Config) TokenSource(ctx context.Context, t *Token) TokenSource { +func (c *Config) TokenSource(ctx context.Context, t *Token, opts ...AuthCodeOption) TokenSource { tkr := &tokenRefresher{ ctx: ctx, conf: c, + opts: opts, } if t != nil { tkr.refreshToken = t.RefreshToken @@ -266,6 +267,7 @@ type tokenRefresher struct { ctx context.Context // used to get HTTP requests conf *Config refreshToken string + opts []AuthCodeOption } // WARNING: Token is not safe for concurrent access, as it @@ -277,10 +279,15 @@ func (tf *tokenRefresher) Token() (*Token, error) { return nil, errors.New("oauth2: token expired and refresh token is not set") } - tk, err := retrieveToken(tf.ctx, tf.conf, url.Values{ + v := url.Values{ "grant_type": {"refresh_token"}, "refresh_token": {tf.refreshToken}, - }) + } + for _, opt := range tf.opts { + opt.setValue(v) + } + + tk, err := retrieveToken(tf.ctx, tf.conf, v) if err != nil { return nil, err