Skip to content

Commit

Permalink
BREAKING CHANGE: remove shouldProceedWithEmailAuthenticator for idx m…
Browse files Browse the repository at this point in the history
…odule
  • Loading branch information
shuowu committed Aug 16, 2022
1 parent 371c426 commit 7bf4077
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 74 deletions.
41 changes: 0 additions & 41 deletions lib/idx/remediators/AuthenticatorVerificationData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,55 +11,14 @@
* See the License for the specific language governing permissions and limitations under the License.
*/


import { AuthSdkError } from '../../errors';
import { AuthenticatorData, AuthenticatorDataValues } from './Base/AuthenticatorData';
import { IdxRemediation, RemediateOptions } from '../types';

export type AuthenticatorVerificationDataValues = AuthenticatorDataValues;

export class AuthenticatorVerificationData extends AuthenticatorData<AuthenticatorVerificationDataValues> {
static remediationName = 'authenticator-verification-data';

shouldProceedWithEmailAuthenticator: boolean; // will be removed in next major version

constructor(
remediation: IdxRemediation,
values: AuthenticatorDataValues = {},
options: RemediateOptions = {}
) {
super(remediation, values);

// will be removed in next major version
this.shouldProceedWithEmailAuthenticator = options.shouldProceedWithEmailAuthenticator !== false
&& this.authenticator.methods.length === 1
&& this.authenticator.methods[0].type === 'email';
}

canRemediate() {
// auto proceed if there is only one method (will be removed in next major version)
if (this.shouldProceedWithEmailAuthenticator !== false) {
return true;
}
return super.canRemediate();
}

mapAuthenticator() {
// auto proceed with the only methodType option
if (this.shouldProceedWithEmailAuthenticator !== false) {
const authenticatorFromRemediation = this.getAuthenticatorFromRemediation();
return authenticatorFromRemediation.form?.value.reduce((acc, curr) => {
if (curr.value) {
acc[curr.name] = curr.value;
} else if (curr.options) {
acc[curr.name] = curr.options![0].value;
} else {
throw new AuthSdkError(`Unsupported authenticator data type: ${curr}`);
}
return acc;
}, {});
}

return this.getAuthenticatorData();
}

Expand Down
3 changes: 0 additions & 3 deletions lib/idx/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ function initializeValues(options: RunOptions) {
'step',
'useGenericRemediator',
'exchangeCodeForTokens',
'shouldProceedWithEmailAuthenticator'
];
const values = { ...options };
knownOptions.forEach(option => {
Expand Down Expand Up @@ -164,7 +163,6 @@ async function getDataFromRemediate(authClient, data: RunData): Promise<RunData>
actions,
flow,
step,
shouldProceedWithEmailAuthenticator, // will be removed in next major version
useGenericRemediator,
} = options;

Expand Down Expand Up @@ -192,7 +190,6 @@ async function getDataFromRemediate(authClient, data: RunData): Promise<RunData>
actions,
flow,
step,
shouldProceedWithEmailAuthenticator, // will be removed in next major version
useGenericRemediator,
}
);
Expand Down
1 change: 0 additions & 1 deletion lib/idx/types/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export interface IntrospectOptions extends IdxOptions {
export interface RemediateOptions extends IdxOptions {
remediators?: RemediationFlow;
actions?: RemediateAction[];
shouldProceedWithEmailAuthenticator?: boolean; // will be removed in next major version
useGenericRemediator?: boolean; // beta
}

Expand Down
23 changes: 0 additions & 23 deletions test/spec/idx/authenticate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1219,29 +1219,6 @@ describe('idx/authenticate', () => {
});
});

it('can auto select email methodType as authenticator verification data', async () => {
const {
authClient,
verificationDataResponse,
verifyEmailResponse
} = testContext;

jest.spyOn(verificationDataResponse, 'proceed').mockResolvedValue(verifyEmailResponse);
jest.spyOn(mocked.introspect, 'introspect').mockResolvedValue(verificationDataResponse);
const res = await authenticate(authClient);
expect(verificationDataResponse.proceed).toHaveBeenCalledWith('authenticator-verification-data', {
authenticator: {
id: 'id-email'
}
});
expect(res).toMatchObject({
status: IdxStatus.PENDING,
nextStep: {
name: 'challenge-authenticator'
}
});
});

it('returns a PENDING error if an invalid code is provided', async () => {
const {
authClient,
Expand Down
6 changes: 0 additions & 6 deletions test/spec/idx/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,11 @@ describe('idx/run', () => {
const flow = 'register';
const username = 'x';
const password = 'y';
const shouldProceedWithEmailAuthenticator = false;
const options: AuthenticationOptions = {
username,
password,
flow,
useGenericRemediator: true,
shouldProceedWithEmailAuthenticator // will be removed in next major version
};
const values = {
username,
Expand All @@ -243,7 +241,6 @@ describe('idx/run', () => {
flow,
flowMonitor,
useGenericRemediator: true,
shouldProceedWithEmailAuthenticator, // will be removed in next major version
});
});

Expand All @@ -260,12 +257,10 @@ describe('idx/run', () => {
const flow = 'register';
const username = 'x';
const password = 'y';
const shouldProceedWithEmailAuthenticator = false;
const options: AuthenticationOptions = {
username,
password,
flow,
shouldProceedWithEmailAuthenticator // will be removed in next major version
};
const values = {
username,
Expand All @@ -280,7 +275,6 @@ describe('idx/run', () => {
actions,
flow,
flowMonitor,
shouldProceedWithEmailAuthenticator, // will be removed in next major version
useGenericRemediator: true,
});
});
Expand Down

0 comments on commit 7bf4077

Please sign in to comment.