Skip to content

Commit

Permalink
fix(idx): allow proceed when saved idxResponse is available - OKTA-51…
Browse files Browse the repository at this point in the history
  • Loading branch information
shuowu committed Jul 11, 2022
1 parent dd3078f commit 917b5d3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Changelog

# 6.7.2
## 6.7.3

### Fixes

- [#1255](https://github.com/okta/okta-auth-js/pull/1255) IDX: allows `idx.proceed` when saved idx response is available

## 6.7.2

### Fixes

Expand Down
4 changes: 3 additions & 1 deletion lib/idx/proceed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions test/spec/idx/authenticate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ describe('idx/authenticate', () => {
clear: () => {},
save: () => {},
saveIdxResponse: () => {},
loadIdxResponse: () => {},
},
token: {
exchangeCodeForTokens: () => Promise.resolve(tokenResponse)
Expand Down
10 changes: 9 additions & 1 deletion test/spec/idx/proceed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe('idx/proceed', () => {
urls: { authorizeUrl: 'meta-authorizeUrl' },
ignoreSignature: true,
};
const savedIdxResponse = { stateHandle: 'fake-stateHandle' };
const authClient = {
options: {
issuer,
Expand All @@ -48,6 +49,7 @@ describe('idx/proceed', () => {
transactionManager: {
exists: () => true,
load: () => transactionMeta,
loadIdxResponse: () => {},
clear: () => {},
save: () => {},
},
Expand All @@ -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);
Expand Down

0 comments on commit 917b5d3

Please sign in to comment.