Skip to content

Commit

Permalink
rebased on ag-466786-remeidate-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredperreault-okta committed Mar 23, 2022
1 parent 3b19410 commit a2ea1d1
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 522 deletions.
51 changes: 0 additions & 51 deletions lib/idx/idx-js/introspect.ts

This file was deleted.

91 changes: 0 additions & 91 deletions lib/idx/idx-js/v1/generateIdxAction.ts

This file was deleted.

49 changes: 0 additions & 49 deletions lib/idx/idx-js/v1/makeIdxState.ts

This file was deleted.

9 changes: 7 additions & 2 deletions lib/idx/idxState/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ export function validateVersionConfig(version) {
parsersForVersion(version); // will throw for invalid version
}

export function makeIdxState ( authClient: OktaAuthInterface, rawIdxResponse: RawIdxResponse, toPersist: {} = {} ): IdxResponse {
export function makeIdxState (
authClient: OktaAuthInterface,
rawIdxResponse: RawIdxResponse,
toPersist: {} = {},
requestDidSucceed: boolean,
): IdxResponse {
const version = rawIdxResponse?.version ?? IDX_API_VERSION;
validateVersionConfig(version);

const { makeIdxState } = parsersForVersion(version);
return makeIdxState(authClient, rawIdxResponse, toPersist);
return makeIdxState(authClient, rawIdxResponse, toPersist, requestDidSucceed);
}
8 changes: 5 additions & 3 deletions lib/idx/idxState/v1/generateIdxAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const generateDirectFetch = function generateDirectFetch(authClient: OktaAuthInt
withCredentials: toPersist?.withCredentials ?? true
});

return makeIdxState(authClient, { ...response }, toPersist);
return makeIdxState(authClient, { ...response }, toPersist, true);
}
catch (err) {
if (!(err instanceof AuthApiError) || !err?.xhr) {
Expand All @@ -56,15 +56,17 @@ const generateDirectFetch = function generateDirectFetch(authClient: OktaAuthInt
const payload = response.responseJSON || JSON.parse(response.responseText);
const wwwAuthHeader = response.headers['WWW-Authenticate'] || response.headers['www-authenticate'];

const idxResponse = makeIdxState(authClient, { ...payload }, toPersist);
const idxResponse = makeIdxState(authClient, { ...payload }, toPersist, false);
if (response.status === 401 && wwwAuthHeader === 'Oktadevicejwt realm="Okta Device"') {
// Okta server responds 401 status code with WWW-Authenticate header and new remediation
// so that the iOS/MacOS credential SSO extension (Okta Verify) can intercept
// the response reaches here when Okta Verify is not installed
// set `stepUp` to true if flow should be continued without showing any errors
idxResponse.stepUp = true;
}
return idxResponse;

// Throw IDX response if request did not succeed. This behavior will be removed in version 7.0: OKTA-481844
throw idxResponse;
}
};
};
Expand Down
12 changes: 9 additions & 3 deletions lib/idx/idxState/v1/makeIdxState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@
*/

import { IdxResponse } from '../../types/idx-js';
import { OktaAuthInterface } from '../../../types'; // auth-js/types
import { OktaAuthInterface, RawIdxResponse } from '../../../types'; // auth-js/types
import { parseIdxResponse } from './idxResponseParser';

export function makeIdxState( authClient: OktaAuthInterface, idxResponse, toPersist ): IdxResponse {
export function makeIdxState(
authClient: OktaAuthInterface,
idxResponse: RawIdxResponse,
toPersist,
requestDidSucceed: boolean
): IdxResponse {
const rawIdxResponse = idxResponse;
const { remediations, context, actions } = parseIdxResponse( authClient, idxResponse, toPersist );
const neededToProceed = [...remediations];
Expand All @@ -35,7 +40,7 @@ export function makeIdxState( authClient: OktaAuthInterface, idxResponse, toPers
};

const findCode = item => item.name === 'interaction_code';
const interactionCode = rawIdxResponse.successWithInteractionCode?.value.find( findCode ).value;
const interactionCode = rawIdxResponse.successWithInteractionCode?.value?.find( findCode )?.value as string;

return {
proceed,
Expand All @@ -45,5 +50,6 @@ export function makeIdxState( authClient: OktaAuthInterface, idxResponse, toPers
rawIdxState: rawIdxResponse,
interactionCode,
toPersist,
requestDidSucceed,
};
}
2 changes: 1 addition & 1 deletion lib/idx/introspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,5 @@ export async function introspect (
}

const { withCredentials } = options;
return makeIdxState(authClient, rawIdxResponse!, { withCredentials });
return makeIdxState(authClient, rawIdxResponse!, { withCredentials }, requestDidSucceed);
}
Loading

0 comments on commit a2ea1d1

Please sign in to comment.