@@ -209,7 +209,7 @@ RxAmplify.Auth.signIn("username", "password")
209
209
func signIn (username : String , password : String ) async {
210
210
do {
211
211
let signInResult = try await Amplify.Auth .signIn (
212
- username : username,
212
+ username : username,
213
213
password : password
214
214
)
215
215
if signInResult.isSignedIn {
@@ -230,7 +230,7 @@ func signIn(username: String, password: String) async {
230
230
func signIn (username : String , password : String ) -> AnyCancellable {
231
231
Amplify.Publisher .create {
232
232
try await Amplify.Auth .signIn (
233
- username : username,
233
+ username : username,
234
234
password : password
235
235
)
236
236
}.sink {
@@ -739,7 +739,7 @@ Amplify.Auth.confirmSignIn("code received via SMS",
739
739
``` kotlin
740
740
try {
741
741
val result = Amplify .Auth .confirmSignIn(" code received via SMS" )
742
- Log .i(" AuthQuickstart" , " Confirmed signin: $result " )
742
+ Log .i(" AuthQuickstart" , " Confirmed signin: $result " )
743
743
} catch (error: AuthException ) {
744
744
Log .e(" AuthQuickstart" , " Failed to confirm signin" , error)
745
745
}
@@ -1047,7 +1047,7 @@ To sign in using an external identity provider such as Google, use the `signInWi
1047
1047
1048
1048
### Update Info.plist
1049
1049
1050
- Sign-in with web UI requires the Amplify plugin to show up the sign-in UI inside a webview. After the sign-in process is complete it will redirect back to your app.
1050
+ Sign-in with web UI requires the Amplify plugin to show up the sign-in UI inside a webview. After the sign-in process is complete it will redirect back to your app.
1051
1051
You have to enable this in your app's ` Info.plist ` . Right click Info.plist and then choose Open As > Source Code. Add the following entry in the URL scheme:
1052
1052
1053
1053
``` xml
@@ -1135,17 +1135,28 @@ Your application's users can also sign in using passwordless methods. To learn m
1135
1135
1136
1136
<InlineFilter filters = { [" angular" , " javascript" , " nextjs" , " react" , " react-native" , " vue" ]} >
1137
1137
1138
- To request an OTP code via SMS for authentication, the challenge is passed as the challenge response to the confirm sign in API .
1138
+ Pass ` SMS_OTP ` as the ` preferredChallenge ` when calling the ` signIn ` API in order to initiate a passwordless authentication flow with SMS OTP .
1139
1139
1140
- Amplify will respond appropriately to Cognito and return the challenge as sign in next step: ` CONFIRM_SIGN_IN_WITH_SMS_CODE ` :
1141
1140
1142
1141
``` ts
1143
- const { nextStep } = await confirmSignIn ({
1144
- challengeResponse: " SMS_OTP"
1142
+ const { nextStep : signInNextStep } = await signIn ({
1143
+ username: ' +15551234567' ,
1144
+ options: {
1145
+ authFlowType: ' USER_AUTH' ,
1146
+ preferredChallenge: ' SMS_OTP' ,
1147
+ },
1145
1148
});
1146
1149
1147
- // nextStep.signInStep === 'CONFIRM_SIGN_IN_WITH_SMS_CODE'
1148
- handleNextSignInStep (nextStep );
1150
+ if (signInNextStep .signInStep === ' CONFIRM_SIGN_IN_WITH_SMS_CODE' ) {
1151
+ // prompt user for otp code delivered via SMS
1152
+ const { nextStep : confirmSignInNextStep } = await confirmSignIn ({
1153
+ challengeResponse: ' 123456' ,
1154
+ });
1155
+
1156
+ if (confirmSignInNextStep .signInStep === ' DONE' ) {
1157
+ console .log (' Sign in successful!' );
1158
+ }
1159
+ }
1149
1160
```
1150
1161
1151
1162
</InlineFilter >
@@ -1339,17 +1350,27 @@ func confirmSignIn() -> AnyCancellable {
1339
1350
1340
1351
<InlineFilter filters = { [" angular" , " javascript" , " nextjs" , " react" , " react-native" , " vue" ]} >
1341
1352
1342
- To request an OTP code via email for authentication, the challenge is passed as the challenge response to the confirm sign in API.
1343
-
1344
- Amplify will respond appropriately to Cognito and return the challenge as sign in next step: ` CONFIRM_SIGN_IN_WITH_EMAIL_CODE ` :
1353
+ Pass ` EMAIL_OTP ` as the ` preferredChallenge ` when calling the ` signIn ` API in order to initiate a passwordless authentication flow using email OTP.
1345
1354
1346
1355
``` ts
1347
- const { nextStep } = await confirmSignIn ({
1348
- challengeResponse: " EMAIL_OTP"
1356
+ const { nextStep : signInNextStep } = await signIn ({
1357
+
1358
+ options: {
1359
+ authFlowType: ' USER_AUTH' ,
1360
+ preferredChallenge: ' EMAIL_OTP' ,
1361
+ },
1349
1362
});
1350
1363
1351
- // nextStep.signInStep === 'CONFIRM_SIGN_IN_WITH_EMAIL_CODE'
1352
- handleNextSignInStep (nextStep );
1364
+ if (signInNextStep .signInStep === ' CONFIRM_SIGN_IN_WITH_EMAIL_CODE' ) {
1365
+ // prompt user for otp code delivered via email
1366
+ const { nextStep : confirmSignInNextStep } = await confirmSignIn ({
1367
+ challengeResponse: ' 123456' ,
1368
+ });
1369
+
1370
+ if (confirmSignInNextStep .signInStep === ' DONE' ) {
1371
+ console .log (' Sign in successful!' );
1372
+ }
1373
+ }
1353
1374
```
1354
1375
1355
1376
</InlineFilter >
@@ -1537,22 +1558,27 @@ func confirmSignIn() -> AnyCancellable {
1537
1558
</BlockSwitcher >
1538
1559
1539
1560
</InlineFilter >
1540
-
1561
+
1541
1562
### WebAuthn Passkeys
1542
1563
1543
1564
{ /* blurb with supplemental information about handling sign-in, events, etc. */ }
1544
1565
1545
1566
<InlineFilter filters = { [" angular" , " javascript" , " nextjs" , " react" , " react-native" , " vue" ]} >
1546
1567
1547
- The WebAuthn credential flow is initiated by passing the challenge name to the confirm sign in api .
1568
+ Pass ` WEB_AUTHN ` as the ` preferredChallenge ` in order to initiate the passwordless authentication flow using a WebAuthn credential .
1548
1569
1549
1570
``` ts
1550
- const { nextStep } = await confirmSignIn ({
1551
- challengeResponse: " WEB_AUTHN" ,
1571
+ const { nextStep : signInNextStep } = await signIn ({
1572
+
1573
+ options: {
1574
+ authFlowType: ' USER_AUTH' ,
1575
+ preferredChallenge: ' WEB_AUTHN' ,
1576
+ },
1552
1577
});
1553
1578
1554
- // nextStep.signInStep === 'DONE'
1555
- handleNextSignInStep (nextStep );
1579
+ if (signInNextStep .signInStep === ' DONE' ) {
1580
+ console .log (' Sign in successful!' );
1581
+ }
1556
1582
```
1557
1583
1558
1584
</InlineFilter >
@@ -1664,28 +1690,55 @@ Using WebAuthn sign in may result in a number of possible exception types.
1664
1690
1665
1691
<InlineFilter filters = { [" angular" , " javascript" , " nextjs" , " react" , " react-native" , " vue" , " android" ]} >
1666
1692
1667
- ### Password or SRP
1693
+ ### Password
1668
1694
1669
- Traditional password based authentication is available from the ` USER_AUTH ` flow as well. To initiate this flow from select challenge, either ` PASSWORD ` or ` PASSWORD_SRP ` is passed as the challenge response .
1695
+ Pass either ` PASSWORD ` or ` PASSWORD_SRP ` as the ` preferredChallenge ` in order to initiate a traditional password based authentication flow .
1670
1696
1671
1697
</InlineFilter >
1672
1698
1673
1699
<InlineFilter filters = { [" angular" , " javascript" , " nextjs" , " react" , " react-native" , " vue" ]} >
1674
1700
``` ts
1675
- const { nextStep } = await confirmSignIn ({
1676
- challengeResponse: " PASSWORD_SRP" , // or "PASSWORD"
1701
+ const { nextStep : signInNextStep } = await signIn ({
1702
+
1703
+ password: ' example-password' ,
1704
+ options: {
1705
+ authFlowType: ' USER_AUTH' ,
1706
+ preferredChallenge: ' PASSWORD_SRP' , // or 'PASSWORD'
1707
+ },
1677
1708
});
1678
1709
1679
- // in both cases
1680
- // nextStep.signInStep === 'CONFIRM_SIGN_IN_WITH_PASSWORD'
1681
- handleNextSignInStep (nextStep );
1710
+ if (confirmSignInNextStep .signInStep === ' DONE' ) {
1711
+ console .log (' Sign in successful!' );
1712
+ }
1713
+ ```
1682
1714
1683
- const { nextStep : nextNextStep } = await confirmSignIn ({
1684
- challengeResponse: " Test123#" ,
1715
+
1716
+ ### First Factor Selection
1717
+
1718
+ Omit the ` preferredChallenge ` parameter to discover what first factors are available for a given user.
1719
+
1720
+ The ` confirmSignIn ` API can then be used to select a challenge and initiate the associated authentication flow.
1721
+
1722
+ ``` ts
1723
+ const { nextStep : signInNextStep } = await signIn ({
1724
+ username: ' +15551234567' ,
1725
+ options: {
1726
+ authFlowType: ' USER_AUTH' ,
1727
+ },
1685
1728
});
1686
1729
1687
- // nextNextStep.signInStep === 'DONE'
1688
- handleNextSignInStep (nextNextStep );
1730
+ if (
1731
+ signInNextStep .signInStep === ' CONTINUE_SIGN_IN_WITH_FIRST_FACTOR_SELECTION'
1732
+ ) {
1733
+ // present user with list of available challenges
1734
+ console .log (` Available Challenges: ${signInNextStep .availableChallenges } ` );
1735
+
1736
+ // respond with user selection using `confirmSignIn` API
1737
+ const { nextStep : nextConfirmSignInStep } = await confirmSignIn ({
1738
+ challengeResponse: ' SMS_OTP' , // or 'EMAIL_OTP', 'WEB_AUTHN', 'PASSWORD', 'PASSWORD_SRP'
1739
+ });
1740
+ }
1741
+
1689
1742
```
1690
1743
</InlineFilter >
1691
1744
0 commit comments