Skip to content

Commit fa2a674

Browse files
lancerushingLance Rushing
authored and
Lance Rushing
committed
Add scope to Exchange request
See https://tools.ietf.org/html/rfc6749#section-4.1.1
1 parent cf02433 commit fa2a674

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

oauth2.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ func (c *Config) Exchange(ctx context.Context, code string, opts ...AuthCodeOpti
218218
if c.RedirectURL != "" {
219219
v.Set("redirect_uri", c.RedirectURL)
220220
}
221+
if len(c.Scopes) > 0 {
222+
v.Set("scope", strings.Join(c.Scopes, " "))
223+
}
221224
for _, opt := range opts {
222225
opt.setValue(v)
223226
}

oauth2_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func TestExchangeRequest(t *testing.T) {
110110
if err != nil {
111111
t.Errorf("Failed reading request body: %s.", err)
112112
}
113-
if string(body) != "code=exchange-code&grant_type=authorization_code&redirect_uri=REDIRECT_URL" {
113+
if string(body) != "code=exchange-code&grant_type=authorization_code&redirect_uri=REDIRECT_URL&scope=scope1+scope2" {
114114
t.Errorf("Unexpected exchange payload; got %q", body)
115115
}
116116
w.Header().Set("Content-Type", "application/x-www-form-urlencoded")
@@ -154,7 +154,7 @@ func TestExchangeRequest_CustomParam(t *testing.T) {
154154
if err != nil {
155155
t.Errorf("Failed reading request body: %s.", err)
156156
}
157-
if string(body) != "code=exchange-code&foo=bar&grant_type=authorization_code&redirect_uri=REDIRECT_URL" {
157+
if string(body) != "code=exchange-code&foo=bar&grant_type=authorization_code&redirect_uri=REDIRECT_URL&scope=scope1+scope2" {
158158
t.Errorf("Unexpected exchange payload, %v is found.", string(body))
159159
}
160160
w.Header().Set("Content-Type", "application/x-www-form-urlencoded")
@@ -200,7 +200,7 @@ func TestExchangeRequest_JSONResponse(t *testing.T) {
200200
if err != nil {
201201
t.Errorf("Failed reading request body: %s.", err)
202202
}
203-
if string(body) != "code=exchange-code&grant_type=authorization_code&redirect_uri=REDIRECT_URL" {
203+
if string(body) != "code=exchange-code&grant_type=authorization_code&redirect_uri=REDIRECT_URL&scope=scope1+scope2" {
204204
t.Errorf("Unexpected exchange payload, %v is found.", string(body))
205205
}
206206
w.Header().Set("Content-Type", "application/json")

0 commit comments

Comments
 (0)