-
Notifications
You must be signed in to change notification settings - Fork 1.1k
chore(auth): add js passwordless changes #8129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
b55743c
0e9239c
c00a701
b2fab29
ed812d2
1796a30
506e1b1
aba4e40
1beddce
1995190
b546294
8ef54f5
6227f8b
471df92
947a44b
9d5b919
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1103,13 +1103,148 @@ func socialSignInWithWebUI() -> AnyCancellable { | |
|
||
Your application's users can also sign in using passwordless methods. To learn more, visit the [concepts page for passwordless](/[platform]/build-a-backend/auth/concepts/passwordless/) | ||
|
||
<InlineFilter filters={["angular", "javascript", "nextjs", "react", "react-native", "vue"]}> | ||
|
||
### New auth flow type | ||
|
||
In order to facilitate the new passwordless sign in options, Cognito is introducing a new auth flow type known as `USER_AUTH`. This flow is designed to be flexible and supports both password and passwordless sign in factors. | ||
|
||
```ts | ||
const { nextStep } = await signIn({ | ||
username: state.username, | ||
options: { | ||
authFlowType: "USER_AUTH", | ||
} | ||
}); | ||
``` | ||
|
||
### Sign In with a Preferred Challenge for First Factor | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, be careful with headers, we created 3 new sections on this page. Should only be SMS OTP, Email OTP, WebAuthn Passkeys, and Password or SRP. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we restricted to those 3? I think giving details on the new There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We want to be consistent with the other libraries. We'd provide conceptual introduction to the auth flow on the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good, I'll move it there - that section seems like a logical place for it to live in our doc structure (though I would still prefer it together 🙃) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A good compromise might be to add a |
||
|
||
The USER_AUTH sign in flow will support the following methods of first factor authentication: `WEB_AUTHN`, `EMAIL_OTP`, `SMS_OTP`, `PASSWORD`, and `PASSWORD_SRP`. | ||
scanlonp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
If the desired first factor is known before the sign in flow is initiated it can be passed to the initial sign in call: | ||
|
||
```ts | ||
type AuthFactorType = | ||
| 'WEB_AUTHN' | ||
| 'EMAIL_OTP' | ||
| 'SMS_OTP' | ||
| 'PASSWORD' | ||
| 'PASSWORD_SRP'; | ||
|
||
type SignInOptions = AuthServiceOptions & { | ||
authFlowType?: AuthFlowType; | ||
clientMetadata?: ClientMetadata; | ||
preferredChallenge?: AuthFactorType; | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be confusing to have types here that aren't referenced in the examples; the connection between these types and how to pass as options is unclear. Is there a way we can clarify this? Maybe using the |
||
``` | ||
|
||
```ts | ||
// PASSWORD_SRP / PASSWORD | ||
// sign in with preferred challenge as password | ||
// note password must be provided in same step | ||
const { nextStep } = await signIn({ | ||
username: state.username, | ||
password: state.password, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we use placeholder strings for these? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean a variable with a placeholder string or string literals with a consistent placeholder string? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. string literals, similar to https://docs.amplify.aws/react/build-a-backend/auth/connect-your-frontend/sign-in/#using-the-signin-api |
||
options: { | ||
authFlowType: "USER_AUTH", | ||
preferredChallenge: "PASSWORD_SRP" // or "PASSWORD" | ||
}, | ||
}); | ||
|
||
// nextStep.signInStep === 'DONE' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
handleNextSignInStep(nextStep); | ||
|
||
// WEB_AUTHN | ||
// sign in with preferred challenge as web authn | ||
// no user input required at this step | ||
const { nextStep } = await signIn({ | ||
username: state.username, | ||
options: { | ||
authFlowType: "USER_AUTH", | ||
preferredChallenge: "WEB_AUTHN" | ||
}, | ||
}); | ||
|
||
// nextStep.signInStep === 'DONE' | ||
handleNextSignInStep(nextStep); | ||
|
||
// EMAIL_OTP | ||
// sign in with preferred challenge as email otp | ||
// no user input required at this step | ||
const { nextStep } = await signIn({ | ||
username: state.username, | ||
options: { | ||
authFlowType: "USER_AUTH", | ||
preferredChallenge: "EMAIL_OTP" | ||
}, | ||
}); | ||
|
||
// nextStep.signInStep === 'CONFIRM_SIGN_IN_WITH_EMAIL_CODE' | ||
handleNextSignInStep(nextStep); | ||
|
||
// SMS_OTP | ||
// sign in with preferred challenge as sms otp | ||
// no user input required at this step | ||
const { nextStep } = await signIn({ | ||
username: state.username, | ||
options: { | ||
authFlowType: "USER_AUTH", | ||
preferredChallenge: "SMS_OTP" | ||
}, | ||
}); | ||
|
||
// nextStep.signInStep === 'CONFIRM_SIGN_IN_WITH_SMS_CODE' | ||
handleNextSignInStep(nextStep); | ||
``` | ||
|
||
Note that if the preferred auth factor is not available, the preference will be ignored and the flow will continue to first factor discovery. | ||
jjarvisp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### Passwordless Sign In with First Factor Discovery | ||
|
||
When multiple first factor options are available and none are set as preferred in InitiateAuth API call (or preferred challenge is not available), Amplify JS continues to a new sign in step `CONTINUE_SIGN_IN_WITH_FIRST_FACTOR_SELECTION`: | ||
|
||
```ts | ||
interface ContinueSignInWithFirstFactorSelection { | ||
signInStep: 'CONTINUE_SIGN_IN_WITH_FIRST_FACTOR_SELECTION'; | ||
availableChallenges?: ChallengeName[]; | ||
} | ||
``` | ||
|
||
```ts | ||
const { nextStep } = await signIn({ | ||
username: state.username, | ||
options: { | ||
authFlowType: "USER_AUTH", | ||
} | ||
}); | ||
|
||
// nextStep.signInStep === 'CONTINUE_SIGN_IN_WITH_FIRST_FACTOR_SELECTION' | ||
handleNextSignInStep(nextStep); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should avoid including internal types in the documentation; we should show an example of how to use the availableChallenges instead. |
||
``` | ||
|
||
To initiate an available first factor, the desired first factor type is passed to confirm sign in as the challenge response. The next sections will that step for each `AuthFactorType`. | ||
scanlonp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
</InlineFilter> | ||
|
||
### SMS OTP | ||
|
||
{/* blurb with supplemental information about handling sign-in, events, etc. */} | ||
|
||
<InlineFilter filters={["angular", "javascript", "nextjs", "react", "react-native", "vue"]}> | ||
|
||
{/* */} | ||
To request an OTP code via SMS for authentication, the challenge is passed as the challenge response to the confirm sign in API. | ||
|
||
Amplify JS will respond appropriately to Cognito and return the challenge as sign in next step: `CONFIRM_SIGN_IN_WITH_SMS_CODE`: | ||
scanlonp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```ts | ||
const { nextStep } = await confirmSignIn({ | ||
challengeResponse: "SMS_OTP" | ||
}); | ||
|
||
// nextStep.signInStep === 'CONFIRM_SIGN_IN_WITH_SMS_CODE' | ||
handleNextSignInStep(nextStep); | ||
``` | ||
|
||
</InlineFilter> | ||
<InlineFilter filters={["android"]}> | ||
|
@@ -1134,7 +1269,18 @@ Your application's users can also sign in using passwordless methods. To learn m | |
|
||
<InlineFilter filters={["angular", "javascript", "nextjs", "react", "react-native", "vue"]}> | ||
|
||
{/* */} | ||
To request an OTP code via email for authentication, the challenge is passed as the challenge response to the confirm sign in API. | ||
|
||
Amplify JS will respond appropriately to Cognito and return the challenge as sign in next step: `CONFIRM_SIGN_IN_WITH_EMAIL_CODE`: | ||
scanlonp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```ts | ||
const { nextStep } = await confirmSignIn({ | ||
challengeResponse: "EMAIL_OTP" | ||
}); | ||
|
||
// nextStep.signInStep === 'CONFIRM_SIGN_IN_WITH_EMAIL_CODE' | ||
handleNextSignInStep(nextStep); | ||
``` | ||
|
||
</InlineFilter> | ||
<InlineFilter filters={["android"]}> | ||
|
@@ -1159,7 +1305,18 @@ Your application's users can also sign in using passwordless methods. To learn m | |
|
||
<InlineFilter filters={["angular", "javascript", "nextjs", "react", "react-native", "vue"]}> | ||
|
||
{/* */} | ||
The WebAuthn credential flow is initiated by passing the challenge name to the confirm sign in api. Cognito will respond with credential request options that are used by Amplify JS to begin the authentication ceremony with the local authenticator. | ||
scanlonp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
As no additional user input is required from the application to complete this flow, there is no intermediate sign in step specific to WebAuthn: | ||
scanlonp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```ts | ||
const { nextStep } = await confirmSignIn({ | ||
challengeResponse: "WEB_AUTHN", | ||
}); | ||
|
||
// nextStep.signInStep === 'DONE' | ||
handleNextSignInStep(nextStep); | ||
``` | ||
|
||
</InlineFilter> | ||
<InlineFilter filters={["android"]}> | ||
|
@@ -1177,3 +1334,28 @@ Your application's users can also sign in using passwordless methods. To learn m | |
{/* */} | ||
|
||
</InlineFilter> | ||
|
||
<InlineFilter filters={["angular", "javascript", "nextjs", "react", "react-native", "vue"]}> | ||
|
||
### Password or SRP | ||
|
||
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. | ||
|
||
```ts | ||
const { nextStep } = await confirmSignIn({ | ||
challengeResponse: "PASSWORD_SRP", // or "PASSWORD" | ||
}); | ||
|
||
// in both cases | ||
// nextStep.signInStep === 'CONFIRM_SIGN_IN_WITH_PASSWORD' | ||
handleNextSignInStep(nextStep); | ||
|
||
const { nextStep: nextNextStep } = await confirmSignIn({ | ||
challengeResponse: "Test123#", | ||
}); | ||
|
||
// nextNextStep.signInStep === 'DONE' | ||
handleNextSignInStep(nextNextStep); | ||
``` | ||
|
||
</InlineFilter> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation is off here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, this info should be on the switching authentication flows page I believe.