feat (auth): support for flow type authorization_code in oauth2-redirect.html (#6750)

This commit is contained in:
Ihnat Klimchuk
2021-01-13 07:02:04 +03:00
committed by GitHub
parent 59b42bb38f
commit 2f8bfd03f8
3 changed files with 26 additions and 4 deletions

View File

@@ -28,8 +28,9 @@
isValid = qp.state === sentState
if ((
oauth2.auth.schema.get("flow") === "accessCode"||
oauth2.auth.schema.get("flow") === "authorizationCode"
oauth2.auth.schema.get("flow") === "accessCode" ||
oauth2.auth.schema.get("flow") === "authorizationCode" ||
oauth2.auth.schema.get("flow") === "authorization_code"
) && !oauth2.auth.code) {
if (!isValid) {
oauth2.errCb({

View File

@@ -31,8 +31,9 @@
isValid = qp.state === sentState
if ((
oauth2.auth.schema.get("flow") === "accessCode"||
oauth2.auth.schema.get("flow") === "authorizationCode"
oauth2.auth.schema.get("flow") === "accessCode" ||
oauth2.auth.schema.get("flow") === "authorizationCode" ||
oauth2.auth.schema.get("flow") === "authorization_code"
) && !oauth2.auth.code) {
if (!isValid) {
oauth2.errCb({

View File

@@ -27,6 +27,14 @@ describe("oauth2", () => {
authConfigs: {}
}
let authConfig3 = {
auth: { schema: { get: (key)=> mockSchema[key] }, scopes: Im.List(["scope4","scope5"]) },
authActions: {},
errActions: {},
configs: { oauth2RedirectUrl: "" },
authConfigs: {}
}
beforeEach(() => {
win.open = jest.fn()
})
@@ -114,5 +122,17 @@ describe("oauth2", () => {
windowOpenSpy.mockReset()
})
it("should build authorize url for authorization_code flow", () => {
const windowOpenSpy = jest.spyOn(win, "open")
mockSchema.authorizationUrl = "https://testAuthorizationUrl"
mockSchema.flow = "authorization_code"
oauth2Authorize(authConfig3)
expect(windowOpenSpy.mock.calls.length).toEqual(1)
expect(windowOpenSpy.mock.calls[0][0]).toMatch("https://testAuthorizationUrl?response_type=code&redirect_uri=&scope=scope4%20scope5&state=")
windowOpenSpy.mockReset()
})
})
})