Skip to content

Commit 2f8bfd0

Browse files
feat (auth): support for flow type authorization_code in oauth2-redirect.html (#6750)
1 parent 59b42bb commit 2f8bfd0

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

dev-helpers/oauth2-redirect.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
isValid = qp.state === sentState
2929

3030
if ((
31-
oauth2.auth.schema.get("flow") === "accessCode"||
32-
oauth2.auth.schema.get("flow") === "authorizationCode"
31+
oauth2.auth.schema.get("flow") === "accessCode" ||
32+
oauth2.auth.schema.get("flow") === "authorizationCode" ||
33+
oauth2.auth.schema.get("flow") === "authorization_code"
3334
) && !oauth2.auth.code) {
3435
if (!isValid) {
3536
oauth2.errCb({

dist/oauth2-redirect.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131
isValid = qp.state === sentState
3232

3333
if ((
34-
oauth2.auth.schema.get("flow") === "accessCode"||
35-
oauth2.auth.schema.get("flow") === "authorizationCode"
34+
oauth2.auth.schema.get("flow") === "accessCode" ||
35+
oauth2.auth.schema.get("flow") === "authorizationCode" ||
36+
oauth2.auth.schema.get("flow") === "authorization_code"
3637
) && !oauth2.auth.code) {
3738
if (!isValid) {
3839
oauth2.errCb({

test/unit/core/oauth2-authorize.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ describe("oauth2", () => {
2727
authConfigs: {}
2828
}
2929

30+
let authConfig3 = {
31+
auth: { schema: { get: (key)=> mockSchema[key] }, scopes: Im.List(["scope4","scope5"]) },
32+
authActions: {},
33+
errActions: {},
34+
configs: { oauth2RedirectUrl: "" },
35+
authConfigs: {}
36+
}
37+
3038
beforeEach(() => {
3139
win.open = jest.fn()
3240
})
@@ -114,5 +122,17 @@ describe("oauth2", () => {
114122

115123
windowOpenSpy.mockReset()
116124
})
125+
126+
it("should build authorize url for authorization_code flow", () => {
127+
const windowOpenSpy = jest.spyOn(win, "open")
128+
mockSchema.authorizationUrl = "https://testAuthorizationUrl"
129+
mockSchema.flow = "authorization_code"
130+
131+
oauth2Authorize(authConfig3)
132+
expect(windowOpenSpy.mock.calls.length).toEqual(1)
133+
expect(windowOpenSpy.mock.calls[0][0]).toMatch("https://testAuthorizationUrl?response_type=code&redirect_uri=&scope=scope4%20scope5&state=")
134+
135+
windowOpenSpy.mockReset()
136+
})
117137
})
118138
})

0 commit comments

Comments
 (0)