Skip to content

Commit 1de6010

Browse files
authored
Merge pull request #3666 from AlexanderVangelov/master
OAuth2 authorizationUrl allow extra query parameters ('&' vs '?')
2 parents a3f923e + b6eb232 commit 1de6010

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/core/oauth2-authorize.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ export default function authorize ( { auth, authActions, errActions, configs, au
6464
}
6565
}
6666

67-
let url = [schema.get("authorizationUrl"), query.join("&")].join("?")
67+
let authorizationUrl = schema.get("authorizationUrl")
68+
let url = [authorizationUrl, query.join("&")].join(authorizationUrl.indexOf("?") === -1 ? "?" : "&")
6869

6970
// pass action authorizeOauth2 and authentication data through window
7071
// to authorize with oauth2

test/core/oauth2-authorize.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* eslint-env mocha */
2+
import expect, { createSpy } from "expect"
3+
import { fromJS } from "immutable"
4+
import win from "core/window"
5+
import oauth2Authorize from "core/oauth2-authorize"
6+
7+
describe("oauth2", function () {
8+
9+
let mockSchema = {
10+
flow: "accessCode",
11+
authorizationUrl: "https://testAuthorizationUrl"
12+
}
13+
14+
let authConfig = {
15+
auth: { schema: { get: (key)=> mockSchema[key] } },
16+
authActions: {},
17+
errActions: {},
18+
configs: { oauth2RedirectUrl: "" },
19+
authConfigs: {}
20+
}
21+
22+
describe("authorize redirect", function () {
23+
24+
it("should build authorize url", function() {
25+
win.open = createSpy()
26+
oauth2Authorize(authConfig)
27+
expect(win.open.calls.length).toEqual(1)
28+
expect(win.open.calls[0].arguments[0]).toMatch("https://testAuthorizationUrl?response_type=code&redirect_uri=&state=")
29+
})
30+
31+
it("should append query paramters to authorizeUrl with query parameters", function() {
32+
win.open = createSpy()
33+
mockSchema.authorizationUrl = "https://testAuthorizationUrl?param=1"
34+
oauth2Authorize(authConfig)
35+
expect(win.open.calls.length).toEqual(1)
36+
expect(win.open.calls[0].arguments[0]).toMatch("https://testAuthorizationUrl?param=1&response_type=code&redirect_uri=&state=")
37+
})
38+
})
39+
})

0 commit comments

Comments
 (0)