diff --git a/dev-helpers/oauth2-redirect.html b/dev-helpers/oauth2-redirect.html index f4aaa93b..72fbf81b 100644 --- a/dev-helpers/oauth2-redirect.html +++ b/dev-helpers/oauth2-redirect.html @@ -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({ diff --git a/dist/oauth2-redirect.html b/dist/oauth2-redirect.html index 5e6599a2..8565155d 100644 --- a/dist/oauth2-redirect.html +++ b/dist/oauth2-redirect.html @@ -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({ diff --git a/test/unit/core/oauth2-authorize.js b/test/unit/core/oauth2-authorize.js index ddf2feda..97dbcaaf 100644 --- a/test/unit/core/oauth2-authorize.js +++ b/test/unit/core/oauth2-authorize.js @@ -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() + }) }) })