Skip to content

oauth2: add option to override the url values for refresh token #727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions oauth2.go
Original file line number Diff line number Diff line change
@@ -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