@@ -1120,17 +1120,28 @@ Your application's users can also sign in using passwordless methods. To learn m
1120
1120
1121
1121
<InlineFilter filters = { [" angular" , " javascript" , " nextjs" , " react" , " react-native" , " vue" ]} >
1122
1122
1123
- To request an OTP code via SMS for authentication, the challenge is passed as the challenge response to the confirm sign in API .
1123
+ Pass ` SMS_OTP ` as the ` preferredChallenge ` when calling the ` signIn ` API in order to initiate a passwordless authentication flow with SMS OTP .
1124
1124
1125
- Amplify will respond appropriately to Cognito and return the challenge as sign in next step: ` CONFIRM_SIGN_IN_WITH_SMS_CODE ` :
1126
1125
1127
1126
``` ts
1128
- const { nextStep } = await confirmSignIn ({
1129
- challengeResponse: " SMS_OTP"
1127
+ const { nextStep : signInNextStep } = await signIn ({
1128
+ username: ' +15551234567' ,
1129
+ options: {
1130
+ authFlowType: ' USER_AUTH' ,
1131
+ preferredChallenge: ' SMS_OTP' ,
1132
+ },
1130
1133
});
1131
1134
1132
- // nextStep.signInStep === 'CONFIRM_SIGN_IN_WITH_SMS_CODE'
1133
- handleNextSignInStep (nextStep );
1135
+ if (signInNextStep .signInStep === ' CONFIRM_SIGN_IN_WITH_SMS_CODE' ) {
1136
+ // prompt user for otp code delivered via SMS
1137
+ const { nextStep : confirmSignInNextStep } = await confirmSignIn ({
1138
+ challengeResponse: ' 123456' ,
1139
+ });
1140
+
1141
+ if (confirmSignInNextStep .signInStep === ' DONE' ) {
1142
+ console .log (' Sign in successful!' );
1143
+ }
1144
+ }
1134
1145
```
1135
1146
1136
1147
</InlineFilter >
@@ -1223,17 +1234,27 @@ func confirmSignIn() -> AnyCancellable {
1223
1234
1224
1235
<InlineFilter filters = { [" angular" , " javascript" , " nextjs" , " react" , " react-native" , " vue" ]} >
1225
1236
1226
- To request an OTP code via email for authentication, the challenge is passed as the challenge response to the confirm sign in API.
1227
-
1228
- Amplify will respond appropriately to Cognito and return the challenge as sign in next step: ` CONFIRM_SIGN_IN_WITH_EMAIL_CODE ` :
1237
+ Pass ` EMAIL_OTP ` as the ` preferredChallenge ` when calling the ` signIn ` API in order to initiate a passwordless authentication flow using email OTP.
1229
1238
1230
1239
``` ts
1231
- const { nextStep } = await confirmSignIn ({
1232
- challengeResponse: " EMAIL_OTP"
1240
+ const { nextStep : signInNextStep } = await signIn ({
1241
+
1242
+ options: {
1243
+ authFlowType: ' USER_AUTH' ,
1244
+ preferredChallenge: ' EMAIL_OTP' ,
1245
+ },
1233
1246
});
1234
1247
1235
- // nextStep.signInStep === 'CONFIRM_SIGN_IN_WITH_EMAIL_CODE'
1236
- handleNextSignInStep (nextStep );
1248
+ if (signInNextStep .signInStep === ' CONFIRM_SIGN_IN_WITH_EMAIL_CODE' ) {
1249
+ // prompt user for otp code delivered via email
1250
+ const { nextStep : confirmSignInNextStep } = await confirmSignIn ({
1251
+ challengeResponse: ' 123456' ,
1252
+ });
1253
+
1254
+ if (confirmSignInNextStep .signInStep === ' DONE' ) {
1255
+ console .log (' Sign in successful!' );
1256
+ }
1257
+ }
1237
1258
```
1238
1259
1239
1260
</InlineFilter >
@@ -1326,15 +1347,20 @@ func confirmSignIn() -> AnyCancellable {
1326
1347
1327
1348
<InlineFilter filters = { [" angular" , " javascript" , " nextjs" , " react" , " react-native" , " vue" ]} >
1328
1349
1329
- The WebAuthn credential flow is initiated by passing the challenge name to the confirm sign in api .
1350
+ Pass ` WEB_AUTHN ` as the ` preferredChallenge ` in order to initiate the passwordless authentication flow using a WebAuthn credential .
1330
1351
1331
1352
``` ts
1332
- const { nextStep } = await confirmSignIn ({
1333
- challengeResponse: " WEB_AUTHN" ,
1353
+ const { nextStep : signInNextStep } = await signIn ({
1354
+
1355
+ options: {
1356
+ authFlowType: ' USER_AUTH' ,
1357
+ preferredChallenge: ' WEB_AUTHN' ,
1358
+ },
1334
1359
});
1335
1360
1336
- // nextStep.signInStep === 'DONE'
1337
- handleNextSignInStep (nextStep );
1361
+ if (signInNextStep .signInStep === ' DONE' ) {
1362
+ console .log (' Sign in successful!' );
1363
+ }
1338
1364
```
1339
1365
1340
1366
</InlineFilter >
@@ -1356,25 +1382,52 @@ handleNextSignInStep(nextStep);
1356
1382
1357
1383
<InlineFilter filters = { [" angular" , " javascript" , " nextjs" , " react" , " react-native" , " vue" ]} >
1358
1384
1359
- ### Password or SRP
1385
+ ### Password
1360
1386
1361
- Traditional password based authentication is available from this flow as well. To initiate this flow from select challenge, either ` PASSWORD ` or ` PASSWORD_SRP ` is passed as the challenge response .
1387
+ Pass either ` PASSWORD ` or ` PASSWORD_SRP ` as the ` preferredChallenge ` in order to initiate a traditional password based authentication flow .
1362
1388
1363
1389
``` ts
1364
- const { nextStep } = await confirmSignIn ({
1365
- challengeResponse: " PASSWORD_SRP" , // or "PASSWORD"
1390
+ const { nextStep : signInNextStep } = await signIn ({
1391
+
1392
+ password: ' example-password' ,
1393
+ options: {
1394
+ authFlowType: ' USER_AUTH' ,
1395
+ preferredChallenge: ' PASSWORD_SRP' , // or 'PASSWORD'
1396
+ },
1366
1397
});
1367
1398
1368
- // in both cases
1369
- // nextStep.signInStep === 'CONFIRM_SIGN_IN_WITH_PASSWORD'
1370
- handleNextSignInStep (nextStep );
1399
+ if (confirmSignInNextStep .signInStep === ' DONE' ) {
1400
+ console .log (' Sign in successful!' );
1401
+ }
1402
+ ```
1403
+
1371
1404
1372
- const { nextStep : nextNextStep } = await confirmSignIn ({
1373
- challengeResponse: " Test123#" ,
1405
+ ### First Factor Selection
1406
+
1407
+ Omit the ` preferredChallenge ` parameter to discover what first factors are available for a given user.
1408
+
1409
+ The ` confirmSignIn ` API can then be used to select a challenge and initiate the associated authentication flow.
1410
+
1411
+ ``` ts
1412
+ const { nextStep : signInNextStep } = await signIn ({
1413
+ username: ' +15551234567' ,
1414
+ options: {
1415
+ authFlowType: ' USER_AUTH' ,
1416
+ },
1374
1417
});
1375
1418
1376
- // nextNextStep.signInStep === 'DONE'
1377
- handleNextSignInStep (nextNextStep );
1419
+ if (
1420
+ signInNextStep .signInStep === ' CONTINUE_SIGN_IN_WITH_FIRST_FACTOR_SELECTION'
1421
+ ) {
1422
+ // present user with list of available challenges
1423
+ console .log (` Available Challenges: ${signInNextStep .availableChallenges } ` );
1424
+
1425
+ // respond with user selection using `confirmSignIn` API
1426
+ const { nextStep : nextConfirmSignInStep } = await confirmSignIn ({
1427
+ challengeResponse: ' SMS_OTP' , // or 'EMAIL_OTP', 'WEB_AUTHN', 'PASSWORD', 'PASSWORD_SRP'
1428
+ });
1429
+ }
1430
+
1378
1431
```
1379
1432
1380
1433
</InlineFilter >
0 commit comments