Skip to content

Commit 9e63ab6

Browse files
committed
chore: add new steps and new flow type
1 parent fc594dd commit 9e63ab6

File tree

3 files changed

+45
-0
lines changed
  • src/pages/[platform]/build-a-backend/auth/connect-your-frontend

3 files changed

+45
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,6 +2030,19 @@ func signIn(username: String, password: String) async {
20302030
20312031
// Prompt the user to enter the Email MFA code they received
20322032
// Then invoke `confirmSignIn` api with the code
2033+
2034+
case .continueSignInWithFirstFactorSelection(let allowedFactors):
2035+
print("Received next step as continue sign in by selecting first factor")
2036+
print("Allowed factors \(allowedFactors)")
2037+
2038+
// Prompt the user to select the first factor they want to use
2039+
// Then invoke `confirmSignIn` api with the factor
2040+
2041+
case .confirmSignInWithPassword:
2042+
print("Received next step as confirm sign in with password")
2043+
2044+
// Prompt the user to enter the password
2045+
// Then invoke `confirmSignIn` api with the password
20332046
20342047
case .continueSignInWithTOTPSetup(let setUpDetails):
20352048
print("Received next step as continue sign in by setting up TOTP")

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ The `signIn` API response will include a `nextStep` property, which can be used
295295
| `confirmSignInWithTOTPCode` | The sign-in must be confirmed with a TOTP code from the user. Complete the process with `confirmSignIn`. |
296296
| `confirmSignInWithSMSMFACode` | The sign-in must be confirmed with a SMS code from the user. Complete the process with `confirmSignIn`. |
297297
| `confirmSignInWithOTP` | The sign-in must be confirmed with a code from the user (sent via SMS or Email). Complete the process with `confirmSignIn`. |
298+
| `confirmSignInWithPassword` | The user must set a new password. Complete the process with `confirmSignIn`. |
299+
| `continueSignInWithFirstFactorSelection` | The user must select their preferred mode of First Factor authentication. Complete the process with `confirmSignIn`. |
298300
| `continueSignInWithMFASelection` | The user must select their mode of MFA verification before signing in. Complete the process with `confirmSignIn`. |
299301
| `continueSignInWithMFASetupSelection` | The user must select their mode of MFA verification to setup. Complete the process by passing either `MFAType.email.challengeResponse` or `MFAType.totp.challengeResponse ` to `confirmSignIn`. |
300302
| `continueSignInWithTOTPSetup` | The TOTP setup process must be continued. Complete the process with `confirmSignIn`. |
@@ -615,6 +617,8 @@ Following sign in, you will receive a `nextStep` in the sign-in result of one of
615617
| `confirmSignInWithTOTPCode` | The sign-in must be confirmed with a TOTP code from the user. Complete the process with `confirmSignIn`. |
616618
| `confirmSignInWithSMSMFACode` | The sign-in must be confirmed with a SMS code from the user. Complete the process with `confirmSignIn`. |
617619
| `confirmSignInWithOTP` | The sign-in must be confirmed with a code from the user (sent via SMS or Email). Complete the process with `confirmSignIn`. |
620+
| `confirmSignInWithPassword` | The user must set a new password. Complete the process with `confirmSignIn`. |
621+
| `continueSignInWithFirstFactorSelection` | The user must select their preferred mode of First Factor authentication. Complete the process with `confirmSignIn`. |
618622
| `continueSignInWithMFASelection` | The user must select their mode of MFA verification before signing in. Complete the process with `confirmSignIn`. |
619623
| `continueSignInWithMFASetupSelection` | The user must select their mode of MFA verification to setup. Complete the process by passing either `MFAType.email.challengeResponse` or `MFAType.totp.challengeResponse ` to `confirmSignIn`. |
620624
| `continueSignInWithTOTPSetup` | The TOTP setup process must be continued. Complete the process with `confirmSignIn`. |

src/pages/[platform]/build-a-backend/auth/connect-your-frontend/switching-authentication-flows/index.mdx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ For client side authentication there are four different flows that can be config
4040

4141
4. `customWithoutSRP`: The `customWithoutSRP` flow is used to start authentication flow **WITHOUT** SRP and then use a series of challenge and response cycles that can be customized to meet different requirements.
4242

43+
5. `userAuth`: The `userAuth` flow is a choice-based authentication flow that allows the user to choose from the list of available authentication methods. This flow is useful when you want to provide the user with the option to choose the authentication method. The choices that may be available to the user are `emailOTP`, `smsOTP`, `webAuthn`, `password` or `passwordSRP`.
44+
4345
`Auth` can be configured to use the different flows at runtime by calling `signIn` with `AuthSignInOptions`'s `authFlowType` as `AuthFlowType.userPassword`, `AuthFlowType.customAuthWithoutSrp` or `AuthFlowType.customAuthWithSrp`. If you do not specify the `AuthFlowType` in `AuthSignInOptions`, the default flow (`AuthFlowType.userSRP`) will be used.
4446

4547
<Callout>
@@ -50,6 +52,31 @@ Runtime configuration will take precedence and will override any auth flow type
5052

5153
> For more information about authentication flows, please visit [Amazon Cognito developer documentation](https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-authentication-flow.html#amazon-cognito-user-pools-custom-authentication-flow)
5254
55+
## USER_AUTH (Choice-based authentication) flow
56+
57+
A use case for the `USER_AUTH` authentication flow is to provide the user with the option to choose the authentication method. The choices that may be available to the user are `emailOTP`, `smsOTP`, `webAuthn`, `password` or `passwordSRP`.
58+
59+
```swift
60+
let pluginOptions = AWSAuthSignInOptions(
61+
authFlowType: .userAuth)
62+
let signInResult = try await Amplify.Auth.signIn(
63+
username: username,
64+
password: password,
65+
options: .init(pluginOptions: pluginOptions))
66+
guard case .continueSignInWithFirstFactorSelection(let availableFactors) = signInResult.nextStep else {
67+
return
68+
}
69+
print("Available factors: \(availableFactors)")
70+
```
71+
72+
The selection of the authentication method is done by the user. The user can choose from the available factors and proceed with the selected factor. You should call the `confirmSignIn` API with the selected factor to continue the sign-in process. Followign is an example if you want to proceed with the `emailOTP` factor selection:
73+
74+
```swift
75+
// Select emailOTP as the factor
76+
var confirmSignInResult = try await Amplify.Auth.confirmSignIn(
77+
challengeResponse: AuthFactorType.emailOTP.challengeResponse)
78+
```
79+
5380
## USER_PASSWORD_AUTH flow
5481

5582
A use case for the `USER_PASSWORD_AUTH` authentication flow is migrating users into Amazon Cognito
@@ -92,6 +119,7 @@ const backend = defineBackend({
92119
backend.auth.resources.cfnResources.cfnUserPoolClient.explicitAuthFlows = [
93120
"ALLOW_USER_PASSWORD_AUTH",
94121
"ALLOW_USER_SRP_AUTH",
122+
"ALLOW_USER_AUTH",
95123
"ALLOW_REFRESH_TOKEN_AUTH"
96124
];
97125
// highlight-end

0 commit comments

Comments
 (0)