Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/7.0' into sw-backport-7.0.2-to-7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
shuowu committed Nov 29, 2022
2 parents 741fc5b + 8ff05e7 commit 75c5d43
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 17 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@

- [#1355](https://github.com/okta/okta-auth-js/pull/1355) Adds missing type `currentAuthenticatorEnrollment` to `IdxContext`

## 7.0.2

### Fixes

- [#1335](https://github.com/okta/okta-auth-js/pull/1335) IDX: adds `uiDisplay` property to `IdxContext` type
- [#1336](https://github.com/okta/okta-auth-js/pull/1319) IDX: adds `deviceKnown` property to `IdxAuthenticator` type
- [#1337](https://github.com/okta/okta-auth-js/pull/1337) IDX: fixes account activation flow by removing check for `identify` remediation

## 7.0.1

### Fixes
Expand Down
5 changes: 1 addition & 4 deletions lib/idx/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,14 @@ export async function register(

// Only check at the beginning of the transaction
if (!hasSavedInteractionHandle(authClient)) {
const { enabledFeatures, availableSteps } = await startTransaction(authClient, {
const { enabledFeatures } = await startTransaction(authClient, {
...options,
flow: 'register',
autoRemediate: false
});
if (!options.activationToken && enabledFeatures && !enabledFeatures.includes(IdxFeature.REGISTRATION)) {
throw new AuthSdkError('Registration is not supported based on your current org configuration.');
}
if (options.activationToken && availableSteps?.some(({ name }) => name === 'identify')) {
throw new AuthSdkError('activationToken is not supported based on your current org configuration.');
}
}

return run(authClient, {
Expand Down
10 changes: 10 additions & 0 deletions lib/idx/types/idx-js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export interface IdxAuthenticator {
resend?: Record<string, unknown>;
poll?: Record<string, unknown>;
recover?: Record<string, unknown>;
deviceKnown?: boolean;
}

export interface IdxForm {
Expand Down Expand Up @@ -177,6 +178,7 @@ export interface IdxContext {
type: string;
value: Record<string, unknown>;
};
uiDisplay?: IdxContextUIDisplay
app: {
type: string;
value: Record<string, unknown>;
Expand All @@ -186,6 +188,14 @@ export interface IdxContext {
failure?: IdxRemediation;
}

export interface IdxContextUIDisplay {
type: string;
value: {
label?: string;
buttonLabel?: string;
}
}

export interface IdxMessage {
message: string;
class: string;
Expand Down
2 changes: 2 additions & 0 deletions lib/idx/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export type {
IdxRemediation,
IdxAuthenticator,
IdxActionParams,
IdxContextUIDisplay,

} from './idx-js';
export * from './meta';
export type { FlowIdentifier } from './FlowIdentifier';
Expand Down
25 changes: 13 additions & 12 deletions test/spec/idx/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,26 +321,27 @@ describe('idx/register', () => {
expect(didThrow).toBe(true);
expect(mocked.startTransaction.startTransaction).toHaveBeenCalledWith(authClient, { flow: 'register', autoRemediate: false });
});
it('presence of identify remediation means activationToken is not supported', async () => {
it('presence of identify remediation should not break account activation with activationToken', async () => {
const { authClient, transactionMeta } = testContext;
jest.spyOn(authClient.transactionManager, 'exists').mockReturnValue(false);
authClient.token.prepareTokenParams = jest.fn().mockResolvedValue(transactionMeta);
const identifyResponse = IdxResponseFactory.build({
neededToProceed: [
IdentifyRemediationFactory.build()
IdentifyRemediationFactory.build(),
SelectAuthenticatorEnrollRemediationFactory.build({
value: [
AuthenticatorValueFactory.build({
options: [
PasswordAuthenticatorOptionFactory.build()
]
})
]
})
]
});
jest.spyOn(mocked.introspect, 'introspect').mockResolvedValue(identifyResponse);

let didThrow = false;
try {
await register(authClient, { activationToken: 'fn-activationToken' });
} catch (error) {
didThrow = true;
expect(error).toBeInstanceOf(AuthSdkError);
expect((error as any).errorSummary).toBe('activationToken is not supported based on your current org configuration.');
}
expect(didThrow).toBe(true);
const res = await register(authClient, { activationToken: 'fn-activationToken' });
expect(res.status).toBe(IdxStatus.PENDING);
});
it('with activationToken should not check select-enroll-profile remediation', async () => {
const { authClient, transactionMeta } = testContext;
Expand Down
6 changes: 5 additions & 1 deletion test/types/auth-idx.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
IdxResponse,
IdxTransaction,
IdxTransactionMeta,
IdxTransactionMetaOptions,
IdxContextUIDisplay,
InteractResponse,
OktaAuth,
} from '@okta/okta-auth-js';
Expand All @@ -31,6 +31,10 @@ expectType<IdxTransaction>(await authClient.idx.proceed());
expectType<IdxTransaction>(await authClient.idx.cancel());
expectType<IdxTransaction>(await authClient.idx.authenticate());

const transaction = await authClient.idx.start();
expectType<IdxContextUIDisplay | undefined>(transaction.context.uiDisplay);
expectType<boolean | undefined>(transaction.context.currentAuthenticator.value.deviceKnown);

expectType<InteractResponse>(await authClient.idx.interact());
expectType<IdxResponse>(await authClient.idx.introspect());
expectType<IdxTransaction>(await authClient.idx.proceed());
Expand Down

0 comments on commit 75c5d43

Please sign in to comment.