Skip to content
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
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down