Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OKTA-716396 : fix : add condition to compare stateHandles when loading saved idxResponse only when useGenericRemediator option is false or undefined #1508

Merged
merged 21 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- [#1495](https://github.com/okta/okta-auth-js/pull/1495) add: DPoP support
- [#1507](https://github.com/okta/okta-auth-js/pull/1507) add: new method `getOrRenewAccessToken`
- [#1505](https://github.com/okta/okta-auth-js/pull/1505) add: support of `revokeSessions` param for `OktaPassword` authenticator (can be used in `reset-authenticator` remediation)
- [#1508](https://github.com/okta/okta-auth-js/pull/1508) IDX: add condition to compare stateHandles when loading saved idxResponse only when useGenericRemediator option is false or undefined
- [#1512](https://github.com/okta/okta-auth-js/pull/1512) add: new service `RenewOnTabActivation`

### Bug Fix
Expand Down
6 changes: 5 additions & 1 deletion lib/idx/IdxTransactionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ export function createIdxTransactionManager
}

if (options) {
const { interactionHandle } = options;
const { stateHandle, interactionHandle } = options;
// only perform this check if NOT using generic remediator
if (!options.useGenericRemediator && stateHandle && storedValue.stateHandle !== stateHandle) {
return null;
}
if (interactionHandle && storedValue.interactionHandle !== interactionHandle) {
return null;
}
Expand Down
5 changes: 3 additions & 2 deletions lib/idx/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,14 @@ async function getDataFromIntrospect(authClient: OktaAuthIdxInterface, data: Run
maxAge,
acrValues,
nonce,
useGenericRemediator,
} = options;

let idxResponse;
let meta = getSavedTransactionMeta(authClient, { state, recoveryToken, activationToken }); // may be undefined

if (stateHandle) {
idxResponse = await introspect(authClient, { withCredentials, version, stateHandle });
idxResponse = await introspect(authClient, { withCredentials, version, stateHandle, useGenericRemediator });
} else {
let interactionHandle = meta?.interactionHandle; // may be undefined
if (!interactionHandle) {
Expand All @@ -154,7 +155,7 @@ async function getDataFromIntrospect(authClient: OktaAuthIdxInterface, data: Run
}

// Introspect to get idx response
idxResponse = await introspect(authClient, { withCredentials, version, interactionHandle });
idxResponse = await introspect(authClient, { withCredentials, version, interactionHandle, useGenericRemediator });
}
return { ...data, idxResponse, meta };
}
Expand Down
1 change: 1 addition & 0 deletions lib/idx/types/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export interface IntrospectOptions extends IdxOptions {
interactionHandle?: string;
stateHandle?: string;
version?: string;
useGenericRemediator?: boolean;
}

export interface RemediateOptions extends IdxOptions {
Expand Down
14 changes: 14 additions & 0 deletions test/spec/idx/IdxTransactionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,20 @@ describe('IdxTransactionManager', () => {
expect(res).toBeNull();
});
describe('with options.stateHandle', () => {
it('returns null if options.stateHandle does not match saved stateHandle and useGenericRemediator = undefined', () => {
const { transactionManager, idxResponseStorage, savedResponse } = testContext;
idxResponseStorage.getStorage.mockReturnValue(savedResponse);
const res = transactionManager.loadIdxResponse({ stateHandle: 'a' });
expect(idxResponseStorage.getStorage).toHaveBeenCalled();
expect(res).toBeNull();
});
it('returns savedResponse if options.stateHandle does not match saved stateHandle and useGenericRemediator = true', () => {
const { transactionManager, idxResponseStorage, savedResponse } = testContext;
idxResponseStorage.getStorage.mockReturnValue(savedResponse);
const res = transactionManager.loadIdxResponse({ stateHandle: 'a', useGenericRemediator: true });
expect(idxResponseStorage.getStorage).toHaveBeenCalled();
expect(res).toBe(savedResponse);
});
it('returns data if options.stateHandle matches saved stateHandle', () => {
const { transactionManager, idxResponseStorage, savedResponse } = testContext;
savedResponse.stateHandle = 'a';
Expand Down