Skip to content

Commit f7ad7e5

Browse files
committed
Merge branch 'main' into add-passwordless-android
2 parents 7c8344b + 7a57277 commit f7ad7e5

File tree

1 file changed

+87
-34
lines changed
  • src/pages/[platform]/build-a-backend/auth/connect-your-frontend/sign-in

1 file changed

+87
-34
lines changed

src/pages/[platform]/build-a-backend/auth/connect-your-frontend/sign-in/index.mdx

Lines changed: 87 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ RxAmplify.Auth.signIn("username", "password")
209209
func signIn(username: String, password: String) async {
210210
do {
211211
let signInResult = try await Amplify.Auth.signIn(
212-
username: username,
212+
username: username,
213213
password: password
214214
)
215215
if signInResult.isSignedIn {
@@ -230,7 +230,7 @@ func signIn(username: String, password: String) async {
230230
func signIn(username: String, password: String) -> AnyCancellable {
231231
Amplify.Publisher.create {
232232
try await Amplify.Auth.signIn(
233-
username: username,
233+
username: username,
234234
password: password
235235
)
236236
}.sink {
@@ -739,7 +739,7 @@ Amplify.Auth.confirmSignIn("code received via SMS",
739739
```kotlin
740740
try {
741741
val result = Amplify.Auth.confirmSignIn("code received via SMS")
742-
Log.i("AuthQuickstart", "Confirmed signin: $result")
742+
Log.i("AuthQuickstart", "Confirmed signin: $result")
743743
} catch (error: AuthException) {
744744
Log.e("AuthQuickstart", "Failed to confirm signin", error)
745745
}
@@ -1047,7 +1047,7 @@ To sign in using an external identity provider such as Google, use the `signInWi
10471047

10481048
### Update Info.plist
10491049

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.
10511051
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:
10521052

10531053
```xml
@@ -1135,17 +1135,28 @@ Your application's users can also sign in using passwordless methods. To learn m
11351135

11361136
<InlineFilter filters={["angular", "javascript", "nextjs", "react", "react-native", "vue"]}>
11371137

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.
11391139

1140-
Amplify will respond appropriately to Cognito and return the challenge as sign in next step: `CONFIRM_SIGN_IN_WITH_SMS_CODE`:
11411140

11421141
```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+
},
11451148
});
11461149

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+
}
11491160
```
11501161

11511162
</InlineFilter>
@@ -1339,17 +1350,27 @@ func confirmSignIn() -> AnyCancellable {
13391350

13401351
<InlineFilter filters={["angular", "javascript", "nextjs", "react", "react-native", "vue"]}>
13411352

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.
13451354

13461355
```ts
1347-
const { nextStep } = await confirmSignIn({
1348-
challengeResponse: "EMAIL_OTP"
1356+
const { nextStep: signInNextStep } = await signIn({
1357+
username: '[email protected]',
1358+
options: {
1359+
authFlowType: 'USER_AUTH',
1360+
preferredChallenge: 'EMAIL_OTP',
1361+
},
13491362
});
13501363

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+
}
13531374
```
13541375

13551376
</InlineFilter>
@@ -1537,22 +1558,27 @@ func confirmSignIn() -> AnyCancellable {
15371558
</BlockSwitcher>
15381559

15391560
</InlineFilter>
1540-
1561+
15411562
### WebAuthn Passkeys
15421563

15431564
{/* blurb with supplemental information about handling sign-in, events, etc. */}
15441565

15451566
<InlineFilter filters={["angular", "javascript", "nextjs", "react", "react-native", "vue"]}>
15461567

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.
15481569

15491570
```ts
1550-
const { nextStep } = await confirmSignIn({
1551-
challengeResponse: "WEB_AUTHN",
1571+
const { nextStep: signInNextStep } = await signIn({
1572+
username: '[email protected]',
1573+
options: {
1574+
authFlowType: 'USER_AUTH',
1575+
preferredChallenge: 'WEB_AUTHN',
1576+
},
15521577
});
15531578

1554-
// nextStep.signInStep === 'DONE'
1555-
handleNextSignInStep(nextStep);
1579+
if (signInNextStep.signInStep === 'DONE') {
1580+
console.log('Sign in successful!');
1581+
}
15561582
```
15571583

15581584
</InlineFilter>
@@ -1664,28 +1690,55 @@ Using WebAuthn sign in may result in a number of possible exception types.
16641690

16651691
<InlineFilter filters={["angular", "javascript", "nextjs", "react", "react-native", "vue", "android"]}>
16661692

1667-
### Password or SRP
1693+
### Password
16681694

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.
16701696

16711697
</InlineFilter>
16721698

16731699
<InlineFilter filters={["angular", "javascript", "nextjs", "react", "react-native", "vue"]}>
16741700
```ts
1675-
const { nextStep } = await confirmSignIn({
1676-
challengeResponse: "PASSWORD_SRP", // or "PASSWORD"
1701+
const { nextStep: signInNextStep } = await signIn({
1702+
username: '[email protected]',
1703+
password: 'example-password',
1704+
options: {
1705+
authFlowType: 'USER_AUTH',
1706+
preferredChallenge: 'PASSWORD_SRP', // or 'PASSWORD'
1707+
},
16771708
});
16781709

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+
```
16821714

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+
},
16851728
});
16861729

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+
16891742
```
16901743
</InlineFilter>
16911744

0 commit comments

Comments
 (0)