fix(auth): support pkce when using basic auth header (#7038)
* support pkce when using basic auth header * test(auth): useBasicAuthenticationWithAccessCodeGrant + usePkceWithAuthorizationCodeGrant
This commit is contained in:
@@ -112,6 +112,40 @@ describe("oauth2", () => {
|
||||
createCodeChallengeSpy.mockReset()
|
||||
})
|
||||
|
||||
|
||||
it("should send code_challenge when using accessCode flow with usePkceWithAuthorizationCodeGrant enabled", () => {
|
||||
const windowOpenSpy = jest.spyOn(win, "open")
|
||||
mockSchema.flow = "accessCode"
|
||||
|
||||
const expectedCodeVerifier = "mock_code_verifier"
|
||||
const expectedCodeChallenge = "mock_code_challenge"
|
||||
|
||||
const generateCodeVerifierSpy = jest.spyOn(utils, "generateCodeVerifier").mockImplementation(() => expectedCodeVerifier)
|
||||
const createCodeChallengeSpy = jest.spyOn(utils, "createCodeChallenge").mockImplementation(() => expectedCodeChallenge)
|
||||
|
||||
authConfig.authConfigs.useBasicAuthenticationWithAccessCodeGrant = true
|
||||
authConfig.authConfigs.usePkceWithAuthorizationCodeGrant = true
|
||||
|
||||
oauth2Authorize(authConfig)
|
||||
expect(win.open.mock.calls.length).toEqual(1)
|
||||
|
||||
const actualUrl = new URLSearchParams(win.open.mock.calls[0][0])
|
||||
expect(actualUrl.get("code_challenge")).toBe(expectedCodeChallenge)
|
||||
expect(actualUrl.get("code_challenge_method")).toBe("S256")
|
||||
|
||||
expect(createCodeChallengeSpy.mock.calls.length).toEqual(1)
|
||||
expect(createCodeChallengeSpy.mock.calls[0][0]).toBe(expectedCodeVerifier)
|
||||
|
||||
// The code_verifier should be stored to be able to send in
|
||||
// on the TokenUrl call
|
||||
expect(authConfig.auth.codeVerifier).toBe(expectedCodeVerifier)
|
||||
|
||||
// Restore spies
|
||||
windowOpenSpy.mockReset()
|
||||
generateCodeVerifierSpy.mockReset()
|
||||
createCodeChallengeSpy.mockReset()
|
||||
})
|
||||
|
||||
it("should send code_challenge when using authorization_code flow with usePkceWithAuthorizationCodeGrant enabled", () => {
|
||||
const windowOpenSpy = jest.spyOn(win, "open")
|
||||
mockSchema.flow = "authorization_code"
|
||||
|
||||
Reference in New Issue
Block a user