Skip to content

Commit 9b1a614

Browse files
OAuth2 authorizationUrl with extra query parameters (should include double '?')
1 parent c7cb902 commit 9b1a614

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 redirectUrl", 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 build correct redirectUrl from 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)