@aws-amplify/auth 6.5.1-email-mfa-test.4e655bc.0 → 6.5.1-storage-browser.4db9fef.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/common/AuthErrorStrings.js +2 -2
- package/dist/cjs/common/AuthErrorStrings.js.map +1 -1
- package/dist/cjs/providers/cognito/apis/confirmSignIn.js +2 -2
- package/dist/cjs/providers/cognito/apis/confirmSignIn.js.map +1 -1
- package/dist/cjs/providers/cognito/apis/updateMFAPreference.js +1 -2
- package/dist/cjs/providers/cognito/apis/updateMFAPreference.js.map +1 -1
- package/dist/cjs/providers/cognito/utils/signInHelpers.js +130 -183
- package/dist/cjs/providers/cognito/utils/signInHelpers.js.map +1 -1
- package/dist/esm/common/AuthErrorStrings.mjs +2 -2
- package/dist/esm/common/AuthErrorStrings.mjs.map +1 -1
- package/dist/esm/foundation/factories/serviceClients/cognitoIdentityProvider/constants.d.ts +1 -1
- package/dist/esm/foundation/factories/serviceClients/cognitoIdentityProvider/createAssociateSoftwareTokenClient.d.ts +1 -1
- package/dist/esm/foundation/factories/serviceClients/cognitoIdentityProvider/createChangePasswordClient.d.ts +1 -1
- package/dist/esm/foundation/factories/serviceClients/cognitoIdentityProvider/createConfirmDeviceClient.d.ts +1 -1
- package/dist/esm/foundation/factories/serviceClients/cognitoIdentityProvider/createConfirmForgotPasswordClient.d.ts +1 -1
- package/dist/esm/foundation/factories/serviceClients/cognitoIdentityProvider/createConfirmSignUpClient.d.ts +1 -1
- package/dist/esm/foundation/factories/serviceClients/cognitoIdentityProvider/createDeleteUserAttributesClient.d.ts +1 -1
- package/dist/esm/foundation/factories/serviceClients/cognitoIdentityProvider/createDeleteUserClient.d.ts +1 -1
- package/dist/esm/foundation/factories/serviceClients/cognitoIdentityProvider/createForgetDeviceClient.d.ts +1 -1
- package/dist/esm/foundation/factories/serviceClients/cognitoIdentityProvider/createForgotPasswordClient.d.ts +1 -1
- package/dist/esm/foundation/factories/serviceClients/cognitoIdentityProvider/createGetUserAttributeVerificationCodeClient.d.ts +1 -1
- package/dist/esm/foundation/factories/serviceClients/cognitoIdentityProvider/createGetUserClient.d.ts +1 -1
- package/dist/esm/foundation/factories/serviceClients/cognitoIdentityProvider/createGlobalSignOutClient.d.ts +1 -1
- package/dist/esm/foundation/factories/serviceClients/cognitoIdentityProvider/createInitiateAuthClient.d.ts +1 -1
- package/dist/esm/foundation/factories/serviceClients/cognitoIdentityProvider/createListDevicesClient.d.ts +1 -1
- package/dist/esm/foundation/factories/serviceClients/cognitoIdentityProvider/createResendConfirmationCodeClient.d.ts +1 -1
- package/dist/esm/foundation/factories/serviceClients/cognitoIdentityProvider/createRespondToAuthChallengeClient.d.ts +1 -1
- package/dist/esm/foundation/factories/serviceClients/cognitoIdentityProvider/createRevokeTokenClient.d.ts +1 -1
- package/dist/esm/foundation/factories/serviceClients/cognitoIdentityProvider/createSetUserMFAPreferenceClient.d.ts +1 -1
- package/dist/esm/foundation/factories/serviceClients/cognitoIdentityProvider/createSignUpClient.d.ts +1 -1
- package/dist/esm/foundation/factories/serviceClients/cognitoIdentityProvider/createUpdateDeviceStatusClient.d.ts +1 -1
- package/dist/esm/foundation/factories/serviceClients/cognitoIdentityProvider/createUpdateUserAttributesClient.d.ts +1 -1
- package/dist/esm/foundation/factories/serviceClients/cognitoIdentityProvider/createVerifySoftwareTokenClient.d.ts +1 -1
- package/dist/esm/foundation/factories/serviceClients/cognitoIdentityProvider/createVerifyUserAttributeClient.d.ts +1 -1
- package/dist/esm/foundation/factories/serviceClients/cognitoIdentityProvider/types/sdk.d.ts +3 -24
- package/dist/esm/providers/cognito/apis/confirmSignIn.mjs +2 -2
- package/dist/esm/providers/cognito/apis/confirmSignIn.mjs.map +1 -1
- package/dist/esm/providers/cognito/apis/updateMFAPreference.mjs +1 -2
- package/dist/esm/providers/cognito/apis/updateMFAPreference.mjs.map +1 -1
- package/dist/esm/providers/cognito/types/inputs.d.ts +0 -1
- package/dist/esm/providers/cognito/utils/signInHelpers.d.ts +3 -4
- package/dist/esm/providers/cognito/utils/signInHelpers.mjs +127 -181
- package/dist/esm/providers/cognito/utils/signInHelpers.mjs.map +1 -1
- package/dist/esm/types/models.d.ts +2 -44
- package/package.json +5 -5
- package/src/common/AuthErrorStrings.ts +2 -4
- package/src/foundation/factories/serviceClients/cognitoIdentityProvider/types/sdk.ts +1 -23
- package/src/providers/cognito/apis/confirmSignIn.ts +2 -2
- package/src/providers/cognito/apis/updateMFAPreference.ts +1 -2
- package/src/providers/cognito/types/inputs.ts +0 -1
- package/src/providers/cognito/utils/signInHelpers.ts +166 -240
- package/src/types/models.ts +1 -48
|
@@ -154,110 +154,49 @@ export async function handleMFASetupChallenge({
|
|
|
154
154
|
config,
|
|
155
155
|
}: HandleAuthChallengeRequest): Promise<RespondToAuthChallengeCommandOutput> {
|
|
156
156
|
const { userPoolId, userPoolClientId, userPoolEndpoint } = config;
|
|
157
|
-
|
|
158
|
-
if (challengeResponse === 'EMAIL') {
|
|
159
|
-
return {
|
|
160
|
-
ChallengeName: 'MFA_SETUP',
|
|
161
|
-
Session: session,
|
|
162
|
-
ChallengeParameters: {
|
|
163
|
-
MFAS_CAN_SETUP: '["EMAIL_OTP"]',
|
|
164
|
-
},
|
|
165
|
-
$metadata: {},
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
if (challengeResponse === 'TOTP') {
|
|
170
|
-
return {
|
|
171
|
-
ChallengeName: 'MFA_SETUP',
|
|
172
|
-
Session: session,
|
|
173
|
-
ChallengeParameters: {
|
|
174
|
-
MFAS_CAN_SETUP: '["SOFTWARE_TOKEN_MFA"]',
|
|
175
|
-
},
|
|
176
|
-
$metadata: {},
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const challengeResponses: Record<string, string> = {
|
|
157
|
+
const challengeResponses = {
|
|
181
158
|
USERNAME: username,
|
|
182
159
|
};
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
region: getRegionFromUserPoolId(userPoolId),
|
|
196
|
-
userAgentValue: getAuthUserAgentValue(AuthAction.ConfirmSignIn),
|
|
197
|
-
},
|
|
198
|
-
{
|
|
199
|
-
UserCode: challengeResponse,
|
|
200
|
-
Session: session,
|
|
201
|
-
FriendlyDeviceName: deviceName,
|
|
202
|
-
},
|
|
203
|
-
);
|
|
204
|
-
|
|
205
|
-
signInStore.dispatch({
|
|
206
|
-
type: 'SET_SIGN_IN_SESSION',
|
|
207
|
-
value: Session,
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
const jsonReq: RespondToAuthChallengeCommandInput = {
|
|
211
|
-
ChallengeName: 'MFA_SETUP',
|
|
212
|
-
ChallengeResponses: challengeResponses,
|
|
213
|
-
Session,
|
|
214
|
-
ClientMetadata: clientMetadata,
|
|
215
|
-
ClientId: userPoolClientId,
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
const respondToAuthChallenge = createRespondToAuthChallengeClient({
|
|
219
|
-
endpointResolver: createCognitoUserPoolEndpointResolver({
|
|
220
|
-
endpointOverride: userPoolEndpoint,
|
|
221
|
-
}),
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
return respondToAuthChallenge(
|
|
225
|
-
{ region: getRegionFromUserPoolId(userPoolId) },
|
|
226
|
-
jsonReq,
|
|
227
|
-
);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
const isEmail = /^\S+@\S+\.\S+$/.test(challengeResponse.trim());
|
|
231
|
-
|
|
232
|
-
if (isEmail) {
|
|
233
|
-
challengeResponses.EMAIL = challengeResponse;
|
|
234
|
-
|
|
235
|
-
const jsonReq: RespondToAuthChallengeCommandInput = {
|
|
236
|
-
ChallengeName: 'MFA_SETUP',
|
|
237
|
-
ChallengeResponses: challengeResponses,
|
|
160
|
+
const verifySoftwareToken = createVerifySoftwareTokenClient({
|
|
161
|
+
endpointResolver: createCognitoUserPoolEndpointResolver({
|
|
162
|
+
endpointOverride: userPoolEndpoint,
|
|
163
|
+
}),
|
|
164
|
+
});
|
|
165
|
+
const { Session } = await verifySoftwareToken(
|
|
166
|
+
{
|
|
167
|
+
region: getRegionFromUserPoolId(userPoolId),
|
|
168
|
+
userAgentValue: getAuthUserAgentValue(AuthAction.ConfirmSignIn),
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
UserCode: challengeResponse,
|
|
238
172
|
Session: session,
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
173
|
+
FriendlyDeviceName: deviceName,
|
|
174
|
+
},
|
|
175
|
+
);
|
|
242
176
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
});
|
|
177
|
+
signInStore.dispatch({
|
|
178
|
+
type: 'SET_SIGN_IN_SESSION',
|
|
179
|
+
value: Session,
|
|
180
|
+
});
|
|
248
181
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
182
|
+
const jsonReq: RespondToAuthChallengeCommandInput = {
|
|
183
|
+
ChallengeName: 'MFA_SETUP',
|
|
184
|
+
ChallengeResponses: challengeResponses,
|
|
185
|
+
Session,
|
|
186
|
+
ClientMetadata: clientMetadata,
|
|
187
|
+
ClientId: userPoolClientId,
|
|
188
|
+
};
|
|
254
189
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
'Try passing "EMAIL", "TOTP", a valid email, or OTP code as the challengeResponse.',
|
|
190
|
+
const respondToAuthChallenge = createRespondToAuthChallengeClient({
|
|
191
|
+
endpointResolver: createCognitoUserPoolEndpointResolver({
|
|
192
|
+
endpointOverride: userPoolEndpoint,
|
|
193
|
+
}),
|
|
260
194
|
});
|
|
195
|
+
|
|
196
|
+
return respondToAuthChallenge(
|
|
197
|
+
{ region: getRegionFromUserPoolId(userPoolId) },
|
|
198
|
+
jsonReq,
|
|
199
|
+
);
|
|
261
200
|
}
|
|
262
201
|
|
|
263
202
|
export async function handleSelectMFATypeChallenge({
|
|
@@ -269,9 +208,7 @@ export async function handleSelectMFATypeChallenge({
|
|
|
269
208
|
}: HandleAuthChallengeRequest): Promise<RespondToAuthChallengeCommandOutput> {
|
|
270
209
|
const { userPoolId, userPoolClientId, userPoolEndpoint } = config;
|
|
271
210
|
assertValidationError(
|
|
272
|
-
challengeResponse === 'TOTP' ||
|
|
273
|
-
challengeResponse === 'SMS' ||
|
|
274
|
-
challengeResponse === 'EMAIL',
|
|
211
|
+
challengeResponse === 'TOTP' || challengeResponse === 'SMS',
|
|
275
212
|
AuthValidationErrorCode.IncorrectMFAMethod,
|
|
276
213
|
);
|
|
277
214
|
|
|
@@ -310,6 +247,88 @@ export async function handleSelectMFATypeChallenge({
|
|
|
310
247
|
);
|
|
311
248
|
}
|
|
312
249
|
|
|
250
|
+
export async function handleSMSMFAChallenge({
|
|
251
|
+
challengeResponse,
|
|
252
|
+
clientMetadata,
|
|
253
|
+
session,
|
|
254
|
+
username,
|
|
255
|
+
config,
|
|
256
|
+
}: HandleAuthChallengeRequest): Promise<RespondToAuthChallengeCommandOutput> {
|
|
257
|
+
const { userPoolId, userPoolClientId, userPoolEndpoint } = config;
|
|
258
|
+
const challengeResponses = {
|
|
259
|
+
USERNAME: username,
|
|
260
|
+
SMS_MFA_CODE: challengeResponse,
|
|
261
|
+
};
|
|
262
|
+
const UserContextData = getUserContextData({
|
|
263
|
+
username,
|
|
264
|
+
userPoolId,
|
|
265
|
+
userPoolClientId,
|
|
266
|
+
});
|
|
267
|
+
const jsonReq: RespondToAuthChallengeCommandInput = {
|
|
268
|
+
ChallengeName: 'SMS_MFA',
|
|
269
|
+
ChallengeResponses: challengeResponses,
|
|
270
|
+
Session: session,
|
|
271
|
+
ClientMetadata: clientMetadata,
|
|
272
|
+
ClientId: userPoolClientId,
|
|
273
|
+
UserContextData,
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
const respondToAuthChallenge = createRespondToAuthChallengeClient({
|
|
277
|
+
endpointResolver: createCognitoUserPoolEndpointResolver({
|
|
278
|
+
endpointOverride: userPoolEndpoint,
|
|
279
|
+
}),
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
return respondToAuthChallenge(
|
|
283
|
+
{
|
|
284
|
+
region: getRegionFromUserPoolId(userPoolId),
|
|
285
|
+
userAgentValue: getAuthUserAgentValue(AuthAction.ConfirmSignIn),
|
|
286
|
+
},
|
|
287
|
+
jsonReq,
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
export async function handleSoftwareTokenMFAChallenge({
|
|
291
|
+
challengeResponse,
|
|
292
|
+
clientMetadata,
|
|
293
|
+
session,
|
|
294
|
+
username,
|
|
295
|
+
config,
|
|
296
|
+
}: HandleAuthChallengeRequest): Promise<RespondToAuthChallengeCommandOutput> {
|
|
297
|
+
const { userPoolId, userPoolClientId, userPoolEndpoint } = config;
|
|
298
|
+
const challengeResponses = {
|
|
299
|
+
USERNAME: username,
|
|
300
|
+
SOFTWARE_TOKEN_MFA_CODE: challengeResponse,
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
const UserContextData = getUserContextData({
|
|
304
|
+
username,
|
|
305
|
+
userPoolId,
|
|
306
|
+
userPoolClientId,
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
const jsonReq: RespondToAuthChallengeCommandInput = {
|
|
310
|
+
ChallengeName: 'SOFTWARE_TOKEN_MFA',
|
|
311
|
+
ChallengeResponses: challengeResponses,
|
|
312
|
+
Session: session,
|
|
313
|
+
ClientMetadata: clientMetadata,
|
|
314
|
+
ClientId: userPoolClientId,
|
|
315
|
+
UserContextData,
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
const respondToAuthChallenge = createRespondToAuthChallengeClient({
|
|
319
|
+
endpointResolver: createCognitoUserPoolEndpointResolver({
|
|
320
|
+
endpointOverride: userPoolEndpoint,
|
|
321
|
+
}),
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
return respondToAuthChallenge(
|
|
325
|
+
{
|
|
326
|
+
region: getRegionFromUserPoolId(userPoolId),
|
|
327
|
+
userAgentValue: getAuthUserAgentValue(AuthAction.ConfirmSignIn),
|
|
328
|
+
},
|
|
329
|
+
jsonReq,
|
|
330
|
+
);
|
|
331
|
+
}
|
|
313
332
|
export async function handleCompleteNewPasswordChallenge({
|
|
314
333
|
challengeResponse,
|
|
315
334
|
clientMetadata,
|
|
@@ -823,65 +842,37 @@ export async function getSignInResult(params: {
|
|
|
823
842
|
case 'MFA_SETUP': {
|
|
824
843
|
const { signInSession, username } = signInStore.getState();
|
|
825
844
|
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
const isEmailMfaSetupAvailable = allowedMfaSetupTypes.includes('EMAIL');
|
|
833
|
-
|
|
834
|
-
if (isTotpMfaSetupAvailable && isEmailMfaSetupAvailable) {
|
|
835
|
-
return {
|
|
836
|
-
isSignedIn: false,
|
|
837
|
-
nextStep: {
|
|
838
|
-
signInStep: 'CONTINUE_SIGN_IN_WITH_MFA_SETUP_SELECTION',
|
|
839
|
-
allowedMFATypes: allowedMfaSetupTypes,
|
|
840
|
-
},
|
|
841
|
-
};
|
|
842
|
-
}
|
|
843
|
-
|
|
844
|
-
if (isEmailMfaSetupAvailable) {
|
|
845
|
-
return {
|
|
846
|
-
isSignedIn: false,
|
|
847
|
-
nextStep: {
|
|
848
|
-
signInStep: 'CONTINUE_SIGN_IN_WITH_EMAIL_SETUP',
|
|
849
|
-
},
|
|
850
|
-
};
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
if (isTotpMfaSetupAvailable) {
|
|
854
|
-
const associateSoftwareToken = createAssociateSoftwareTokenClient({
|
|
855
|
-
endpointResolver: createCognitoUserPoolEndpointResolver({
|
|
856
|
-
endpointOverride: authConfig.userPoolEndpoint,
|
|
857
|
-
}),
|
|
858
|
-
});
|
|
859
|
-
const { Session, SecretCode: secretCode } =
|
|
860
|
-
await associateSoftwareToken(
|
|
861
|
-
{ region: getRegionFromUserPoolId(authConfig.userPoolId) },
|
|
862
|
-
{
|
|
863
|
-
Session: signInSession,
|
|
864
|
-
},
|
|
865
|
-
);
|
|
866
|
-
|
|
867
|
-
signInStore.dispatch({
|
|
868
|
-
type: 'SET_SIGN_IN_SESSION',
|
|
869
|
-
value: Session,
|
|
845
|
+
if (!isMFATypeEnabled(challengeParameters, 'TOTP'))
|
|
846
|
+
throw new AuthError({
|
|
847
|
+
name: AuthErrorCodes.SignInException,
|
|
848
|
+
message: `Cannot initiate MFA setup from available types: ${getMFATypes(
|
|
849
|
+
parseMFATypes(challengeParameters.MFAS_CAN_SETUP),
|
|
850
|
+
)}`,
|
|
870
851
|
});
|
|
871
852
|
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
}
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
853
|
+
const associateSoftwareToken = createAssociateSoftwareTokenClient({
|
|
854
|
+
endpointResolver: createCognitoUserPoolEndpointResolver({
|
|
855
|
+
endpointOverride: authConfig.userPoolEndpoint,
|
|
856
|
+
}),
|
|
857
|
+
});
|
|
858
|
+
const { Session, SecretCode: secretCode } = await associateSoftwareToken(
|
|
859
|
+
{ region: getRegionFromUserPoolId(authConfig.userPoolId) },
|
|
860
|
+
{
|
|
861
|
+
Session: signInSession,
|
|
862
|
+
},
|
|
863
|
+
);
|
|
864
|
+
signInStore.dispatch({
|
|
865
|
+
type: 'SET_SIGN_IN_SESSION',
|
|
866
|
+
value: Session,
|
|
884
867
|
});
|
|
868
|
+
|
|
869
|
+
return {
|
|
870
|
+
isSignedIn: false,
|
|
871
|
+
nextStep: {
|
|
872
|
+
signInStep: 'CONTINUE_SIGN_IN_WITH_TOTP_SETUP',
|
|
873
|
+
totpSetupDetails: getTOTPSetupDetails(secretCode!, username),
|
|
874
|
+
},
|
|
875
|
+
};
|
|
885
876
|
}
|
|
886
877
|
case 'NEW_PASSWORD_REQUIRED':
|
|
887
878
|
return {
|
|
@@ -922,18 +913,6 @@ export async function getSignInResult(params: {
|
|
|
922
913
|
signInStep: 'CONFIRM_SIGN_IN_WITH_TOTP_CODE',
|
|
923
914
|
},
|
|
924
915
|
};
|
|
925
|
-
case 'EMAIL_OTP':
|
|
926
|
-
return {
|
|
927
|
-
isSignedIn: false,
|
|
928
|
-
nextStep: {
|
|
929
|
-
signInStep: 'CONFIRM_SIGN_IN_WITH_EMAIL_CODE',
|
|
930
|
-
codeDeliveryDetails: {
|
|
931
|
-
deliveryMedium:
|
|
932
|
-
challengeParameters.CODE_DELIVERY_DELIVERY_MEDIUM as AuthDeliveryMedium,
|
|
933
|
-
destination: challengeParameters.CODE_DELIVERY_DESTINATION,
|
|
934
|
-
},
|
|
935
|
-
},
|
|
936
|
-
};
|
|
937
916
|
case 'ADMIN_NO_SRP_AUTH':
|
|
938
917
|
break;
|
|
939
918
|
case 'DEVICE_PASSWORD_VERIFIER':
|
|
@@ -1021,6 +1000,14 @@ export async function handleChallengeName(
|
|
|
1021
1000
|
const deviceName = options?.friendlyDeviceName;
|
|
1022
1001
|
|
|
1023
1002
|
switch (challengeName) {
|
|
1003
|
+
case 'SMS_MFA':
|
|
1004
|
+
return handleSMSMFAChallenge({
|
|
1005
|
+
challengeResponse,
|
|
1006
|
+
clientMetadata,
|
|
1007
|
+
session,
|
|
1008
|
+
username,
|
|
1009
|
+
config,
|
|
1010
|
+
});
|
|
1024
1011
|
case 'SELECT_MFA_TYPE':
|
|
1025
1012
|
return handleSelectMFATypeChallenge({
|
|
1026
1013
|
challengeResponse,
|
|
@@ -1063,11 +1050,8 @@ export async function handleChallengeName(
|
|
|
1063
1050
|
username,
|
|
1064
1051
|
tokenOrchestrator,
|
|
1065
1052
|
);
|
|
1066
|
-
case 'SMS_MFA':
|
|
1067
1053
|
case 'SOFTWARE_TOKEN_MFA':
|
|
1068
|
-
|
|
1069
|
-
return handleMFAChallenge({
|
|
1070
|
-
challengeName,
|
|
1054
|
+
return handleSoftwareTokenMFAChallenge({
|
|
1071
1055
|
challengeResponse,
|
|
1072
1056
|
clientMetadata,
|
|
1073
1057
|
session,
|
|
@@ -1078,7 +1062,7 @@ export async function handleChallengeName(
|
|
|
1078
1062
|
// TODO: remove this error message for production apps
|
|
1079
1063
|
throw new AuthError({
|
|
1080
1064
|
name: AuthErrorCodes.SignInException,
|
|
1081
|
-
message: `An error occurred during the sign in process.
|
|
1065
|
+
message: `An error occurred during the sign in process.
|
|
1082
1066
|
${challengeName} challengeName returned by the underlying service was not addressed.`,
|
|
1083
1067
|
});
|
|
1084
1068
|
}
|
|
@@ -1086,7 +1070,6 @@ export async function handleChallengeName(
|
|
|
1086
1070
|
export function mapMfaType(mfa: string): CognitoMFAType {
|
|
1087
1071
|
let mfaType: CognitoMFAType = 'SMS_MFA';
|
|
1088
1072
|
if (mfa === 'TOTP') mfaType = 'SOFTWARE_TOKEN_MFA';
|
|
1089
|
-
if (mfa === 'EMAIL') mfaType = 'EMAIL_OTP';
|
|
1090
1073
|
|
|
1091
1074
|
return mfaType;
|
|
1092
1075
|
}
|
|
@@ -1094,7 +1077,6 @@ export function mapMfaType(mfa: string): CognitoMFAType {
|
|
|
1094
1077
|
export function getMFAType(type?: string): AuthMFAType | undefined {
|
|
1095
1078
|
if (type === 'SMS_MFA') return 'SMS';
|
|
1096
1079
|
if (type === 'SOFTWARE_TOKEN_MFA') return 'TOTP';
|
|
1097
|
-
if (type === 'EMAIL_OTP') return 'EMAIL';
|
|
1098
1080
|
// TODO: log warning for unknown MFA type
|
|
1099
1081
|
}
|
|
1100
1082
|
|
|
@@ -1109,10 +1091,15 @@ export function parseMFATypes(mfa?: string): CognitoMFAType[] {
|
|
|
1109
1091
|
return JSON.parse(mfa) as CognitoMFAType[];
|
|
1110
1092
|
}
|
|
1111
1093
|
|
|
1112
|
-
export function
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1094
|
+
export function isMFATypeEnabled(
|
|
1095
|
+
challengeParams: ChallengeParameters,
|
|
1096
|
+
mfaType: AuthMFAType,
|
|
1097
|
+
): boolean {
|
|
1098
|
+
const { MFAS_CAN_SETUP } = challengeParams;
|
|
1099
|
+
const mfaTypes = getMFATypes(parseMFATypes(MFAS_CAN_SETUP));
|
|
1100
|
+
if (!mfaTypes) return false;
|
|
1101
|
+
|
|
1102
|
+
return mfaTypes.includes(mfaType);
|
|
1116
1103
|
}
|
|
1117
1104
|
|
|
1118
1105
|
export async function assertUserNotAuthenticated() {
|
|
@@ -1243,64 +1230,3 @@ export function getActiveSignInUsername(username: string): string {
|
|
|
1243
1230
|
|
|
1244
1231
|
return state.username ?? username;
|
|
1245
1232
|
}
|
|
1246
|
-
|
|
1247
|
-
export async function handleMFAChallenge({
|
|
1248
|
-
challengeName,
|
|
1249
|
-
challengeResponse,
|
|
1250
|
-
clientMetadata,
|
|
1251
|
-
session,
|
|
1252
|
-
username,
|
|
1253
|
-
config,
|
|
1254
|
-
}: HandleAuthChallengeRequest & {
|
|
1255
|
-
challengeName: Extract<
|
|
1256
|
-
ChallengeName,
|
|
1257
|
-
'EMAIL_OTP' | 'SMS_MFA' | 'SOFTWARE_TOKEN_MFA'
|
|
1258
|
-
>;
|
|
1259
|
-
}) {
|
|
1260
|
-
const { userPoolId, userPoolClientId, userPoolEndpoint } = config;
|
|
1261
|
-
|
|
1262
|
-
const challengeResponses: Record<string, string> = {
|
|
1263
|
-
USERNAME: username,
|
|
1264
|
-
};
|
|
1265
|
-
|
|
1266
|
-
if (challengeName === 'EMAIL_OTP') {
|
|
1267
|
-
challengeResponses.EMAIL_OTP_CODE = challengeResponse;
|
|
1268
|
-
}
|
|
1269
|
-
|
|
1270
|
-
if (challengeName === 'SMS_MFA') {
|
|
1271
|
-
challengeResponses.SMS_MFA_CODE = challengeResponse;
|
|
1272
|
-
}
|
|
1273
|
-
|
|
1274
|
-
if (challengeName === 'SOFTWARE_TOKEN_MFA') {
|
|
1275
|
-
challengeResponses.SOFTWARE_TOKEN_MFA_CODE = challengeResponse;
|
|
1276
|
-
}
|
|
1277
|
-
|
|
1278
|
-
const userContextData = getUserContextData({
|
|
1279
|
-
username,
|
|
1280
|
-
userPoolId,
|
|
1281
|
-
userPoolClientId,
|
|
1282
|
-
});
|
|
1283
|
-
|
|
1284
|
-
const jsonReq: RespondToAuthChallengeCommandInput = {
|
|
1285
|
-
ChallengeName: challengeName,
|
|
1286
|
-
ChallengeResponses: challengeResponses,
|
|
1287
|
-
Session: session,
|
|
1288
|
-
ClientMetadata: clientMetadata,
|
|
1289
|
-
ClientId: userPoolClientId,
|
|
1290
|
-
UserContextData: userContextData,
|
|
1291
|
-
};
|
|
1292
|
-
|
|
1293
|
-
const respondToAuthChallenge = createRespondToAuthChallengeClient({
|
|
1294
|
-
endpointResolver: createCognitoUserPoolEndpointResolver({
|
|
1295
|
-
endpointOverride: userPoolEndpoint,
|
|
1296
|
-
}),
|
|
1297
|
-
});
|
|
1298
|
-
|
|
1299
|
-
return respondToAuthChallenge(
|
|
1300
|
-
{
|
|
1301
|
-
region: getRegionFromUserPoolId(userPoolId),
|
|
1302
|
-
userAgentValue: getAuthUserAgentValue(AuthAction.ConfirmSignIn),
|
|
1303
|
-
},
|
|
1304
|
-
jsonReq,
|
|
1305
|
-
);
|
|
1306
|
-
}
|
package/src/types/models.ts
CHANGED
|
@@ -44,7 +44,7 @@ export interface AuthTOTPSetupDetails {
|
|
|
44
44
|
getSetupUri(appName: string, accountName?: string): URL;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
export type AuthMFAType = 'SMS' | 'TOTP'
|
|
47
|
+
export type AuthMFAType = 'SMS' | 'TOTP';
|
|
48
48
|
|
|
49
49
|
export type AuthAllowedMFATypes = AuthMFAType[];
|
|
50
50
|
|
|
@@ -63,20 +63,6 @@ export interface ContinueSignInWithTOTPSetup {
|
|
|
63
63
|
signInStep: 'CONTINUE_SIGN_IN_WITH_TOTP_SETUP';
|
|
64
64
|
totpSetupDetails: AuthTOTPSetupDetails;
|
|
65
65
|
}
|
|
66
|
-
export interface ContinueSignInWithEmailSetup {
|
|
67
|
-
/**
|
|
68
|
-
* Auth step requires user to set up EMAIL as multifactor authentication by associating an email address
|
|
69
|
-
* and entering the OTP.
|
|
70
|
-
*
|
|
71
|
-
* @example
|
|
72
|
-
* ```typescript
|
|
73
|
-
* // Code retrieved from email
|
|
74
|
-
* const emailAddress = 'example@example.com';
|
|
75
|
-
* await confirmSignIn({challengeResponse: emailAddress });
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
signInStep: 'CONTINUE_SIGN_IN_WITH_EMAIL_SETUP';
|
|
79
|
-
}
|
|
80
66
|
export interface ConfirmSignInWithTOTPCode {
|
|
81
67
|
/**
|
|
82
68
|
* Auth step requires user to use TOTP as multifactor authentication by retriving an OTP code from authenticator app.
|
|
@@ -106,21 +92,6 @@ export interface ContinueSignInWithMFASelection {
|
|
|
106
92
|
allowedMFATypes?: AuthAllowedMFATypes;
|
|
107
93
|
}
|
|
108
94
|
|
|
109
|
-
export interface ContinueSignInWithMFASetupSelection {
|
|
110
|
-
/**
|
|
111
|
-
* Auth step requires user to select an mfa option (SMS | TOTP) to setup before continuing the sign-in flow.
|
|
112
|
-
*
|
|
113
|
-
* @example
|
|
114
|
-
* ```typescript
|
|
115
|
-
* await confirmSignIn({challengeResponse:'TOTP'});
|
|
116
|
-
* // OR
|
|
117
|
-
* await confirmSignIn({challengeResponse:'EMAIL'});
|
|
118
|
-
* ```
|
|
119
|
-
*/
|
|
120
|
-
signInStep: 'CONTINUE_SIGN_IN_WITH_MFA_SETUP_SELECTION';
|
|
121
|
-
allowedMFATypes?: AuthAllowedMFATypes;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
95
|
export interface ConfirmSignInWithCustomChallenge {
|
|
125
96
|
/**
|
|
126
97
|
* Auth step requires user to respond to a custom challenge.
|
|
@@ -175,21 +146,6 @@ export interface ConfirmSignInWithSMSCode {
|
|
|
175
146
|
codeDeliveryDetails?: AuthCodeDeliveryDetails;
|
|
176
147
|
}
|
|
177
148
|
|
|
178
|
-
export interface ConfirmSignInWithEmailCode {
|
|
179
|
-
/**
|
|
180
|
-
* Auth step requires user to use EMAIL as multifactor authentication by retrieving a code sent to inbox.
|
|
181
|
-
*
|
|
182
|
-
* @example
|
|
183
|
-
* ```typescript
|
|
184
|
-
* // Code retrieved from email
|
|
185
|
-
* const emailCode = '112233'
|
|
186
|
-
* await confirmSignIn({challengeResponse: emailCode})
|
|
187
|
-
* ```
|
|
188
|
-
*/
|
|
189
|
-
signInStep: 'CONFIRM_SIGN_IN_WITH_EMAIL_CODE';
|
|
190
|
-
codeDeliveryDetails?: AuthCodeDeliveryDetails;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
149
|
export interface ConfirmSignUpStep {
|
|
194
150
|
/**
|
|
195
151
|
* Auth step requires to confirm user's sign-up.
|
|
@@ -225,10 +181,7 @@ export type AuthNextSignInStep<
|
|
|
225
181
|
| ConfirmSignInWithNewPasswordRequired<UserAttributeKey>
|
|
226
182
|
| ConfirmSignInWithSMSCode
|
|
227
183
|
| ConfirmSignInWithTOTPCode
|
|
228
|
-
| ConfirmSignInWithEmailCode
|
|
229
184
|
| ContinueSignInWithTOTPSetup
|
|
230
|
-
| ContinueSignInWithEmailSetup
|
|
231
|
-
| ContinueSignInWithMFASetupSelection
|
|
232
185
|
| ConfirmSignUpStep
|
|
233
186
|
| ResetPasswordStep
|
|
234
187
|
| DoneSignInStep;
|