Skip to content

Commit cf02433

Browse files
lancerushingLance Rushing
authored and
Lance Rushing
committed
Add scope to token refresh request. Closes #447
1 parent 5d25da1 commit cf02433

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

oauth2.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,16 @@ func (tf *tokenRefresher) Token() (*Token, error) {
267267
return nil, errors.New("oauth2: token expired and refresh token is not set")
268268
}
269269

270-
tk, err := retrieveToken(tf.ctx, tf.conf, url.Values{
270+
271+
v := url.Values{
271272
"grant_type": {"refresh_token"},
272273
"refresh_token": {tf.refreshToken},
273-
})
274+
}
275+
if len(tf.conf.Scopes) > 0 {
276+
v.Set("scope", strings.Join(tf.conf.Scopes, " "))
277+
}
278+
279+
tk, err := retrieveToken(tf.ctx, tf.conf, v)
274280

275281
if err != nil {
276282
return nil, err

oauth2_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ func TestTokenRefreshRequest(t *testing.T) {
440440
t.Errorf("Unexpected Content-Type header %q", headerContentType)
441441
}
442442
body, _ := ioutil.ReadAll(r.Body)
443-
if string(body) != "grant_type=refresh_token&refresh_token=REFRESH_TOKEN" {
443+
if string(body) != "grant_type=refresh_token&refresh_token=REFRESH_TOKEN&scope=scope1+scope2" {
444444
t.Errorf("Unexpected refresh token payload %q", body)
445445
}
446446
w.Header().Set("Content-Type", "application/json")

0 commit comments

Comments
 (0)