From 0f54b7646ae997c2af9d8f681c75dcff37c12e05 Mon Sep 17 00:00:00 2001 From: Shuo Wu Date: Mon, 11 Jul 2022 17:02:59 -0400 Subject: [PATCH] fix(idx): allow proceed when saved idxResponse is available - OKTA-513541 --- lib/idx/proceed.ts | 4 +++- test/spec/idx/authenticate.ts | 1 + test/spec/idx/proceed.ts | 10 +++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/idx/proceed.ts b/lib/idx/proceed.ts index 8f910e3dab..f135a85a61 100644 --- a/lib/idx/proceed.ts +++ b/lib/idx/proceed.ts @@ -22,7 +22,9 @@ import { AuthSdkError } from '../errors'; export function canProceed(authClient: OktaAuthIdxInterface, options: ProceedOptions = {}): boolean { const meta = getSavedTransactionMeta(authClient, options); - return !!(meta || options.stateHandle); + const savedIdxResponse = authClient.transactionManager.loadIdxResponse(options); + const stateHandle = savedIdxResponse?.stateHandle || options.stateHandle; + return !!(meta || stateHandle); } export async function proceed( diff --git a/test/spec/idx/authenticate.ts b/test/spec/idx/authenticate.ts index 042f99a496..54dc07a7fe 100644 --- a/test/spec/idx/authenticate.ts +++ b/test/spec/idx/authenticate.ts @@ -116,6 +116,7 @@ describe('idx/authenticate', () => { clear: () => {}, save: () => {}, saveIdxResponse: () => {}, + loadIdxResponse: () => {}, }, token: { exchangeCodeForTokens: () => Promise.resolve(tokenResponse) diff --git a/test/spec/idx/proceed.ts b/test/spec/idx/proceed.ts index b70bbafd0a..8481e22ed7 100644 --- a/test/spec/idx/proceed.ts +++ b/test/spec/idx/proceed.ts @@ -39,6 +39,7 @@ describe('idx/proceed', () => { urls: { authorizeUrl: 'meta-authorizeUrl' }, ignoreSignature: true, }; + const savedIdxResponse = { stateHandle: 'fake-stateHandle' }; const authClient = { options: { issuer, @@ -48,6 +49,7 @@ describe('idx/proceed', () => { transactionManager: { exists: () => true, load: () => transactionMeta, + loadIdxResponse: () => {}, clear: () => {}, save: () => {}, }, @@ -62,16 +64,22 @@ describe('idx/proceed', () => { redirectUri, stateHandle, transactionMeta, + savedIdxResponse, authClient }; }); describe('canProceed', () => { - it('returns true if there is a saved transaction', () => { + it('returns true if there is a saved transaction meta', () => { const { authClient, transactionMeta } = testContext; jest.spyOn(mocked.transactionMeta, 'getSavedTransactionMeta').mockReturnValue(transactionMeta); expect(canProceed(authClient)).toBe(true); }); + it('returns true if there is a saved idxTransaction', () => { + const { authClient, savedIdxResponse } = testContext; + jest.spyOn(authClient.transactionManager, 'loadIdxResponse').mockReturnValue(savedIdxResponse); + expect(canProceed(authClient)).toBe(true); + }); it('returns false if there is no saved transaction', () => { const { authClient } = testContext; jest.spyOn(mocked.transactionMeta, 'getSavedTransactionMeta').mockReturnValue(undefined);