Skip to content

Commit 5f48718

Browse files
feat(auth): update passwordless authentication configuration guide (#8478)
1 parent 368285e commit 5f48718

File tree

3 files changed

+184
-39
lines changed

3 files changed

+184
-39
lines changed

src/pages/[platform]/build-a-backend/auth/concepts/passwordless/index.mdx

Lines changed: 148 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,40 @@ Amplify supports the use of passwordless authentication flows using the followin
3434
- [WebAuthn passkey](#webauthn-passkey)
3535

3636
Passwordless authentication removes the security risks and user friction associated with traditional passwords.
37-
{/* add more color */}
3837

39-
<Callout warning>
38+
## Configure passwordless authentication
4039

41-
**Warning:** Passwordless configuration is currently not available in `defineAuth`. We are currently working towards enabling support for passwordless configurations. [Visit the GitHub issue to track the progress](https://github.com/aws-amplify/amplify-backend/issues/2276)
40+
You can enable passwordless authentication methods directly in your `defineAuth` configuration. Passwordless methods are used alongside traditional password-based authentication, giving users multiple options to sign in.
4241

43-
</Callout>
42+
```ts title="amplify/auth/resource.ts"
43+
import { defineAuth } from '@aws-amplify/backend';
4444

45-
Learn how to enable passwordless sign-in flows by [overriding the Cognito UserPool to enable the sign-in methods below](/[platform]/build-a-backend/auth/modify-resources-with-cdk/#override-cognito-userpool-to-enable-passwordless-sign-in-methods).
45+
export const auth = defineAuth({
46+
loginWith: {
47+
email: {
48+
otpLogin: true // Enable email OTP
49+
}
50+
}
51+
});
52+
```
53+
54+
You can enable multiple passwordless methods simultaneously:
55+
56+
```ts title="amplify/auth/resource.ts"
57+
import { defineAuth } from '@aws-amplify/backend';
58+
59+
export const auth = defineAuth({
60+
loginWith: {
61+
email: {
62+
otpLogin: true // Enable email OTP
63+
},
64+
phone: {
65+
otpLogin: true // Enable SMS OTP
66+
},
67+
webAuthn: true // Enable WebAuthn passkeys
68+
}
69+
});
70+
```
4671

4772
{/* need a section about what a "preferred" factor is */}
4873

@@ -54,23 +79,21 @@ SMS-based authentication uses phone numbers as the identifier and text messages
5479
2. They receive a text message with a time-limited code
5580
3. After the user enters their code they are authenticated
5681

57-
{/* quick blurb of basic usage */}
58-
<InlineFilter filters={["angular", "javascript", "nextjs", "react", "react-native", "vue"]}>
82+
### Configure SMS OTP
5983

60-
{/* */}
61-
62-
</InlineFilter>
63-
<InlineFilter filters={["android"]}>
64-
65-
{/* */}
66-
67-
</InlineFilter>
68-
69-
<InlineFilter filters={["swift"]}>
84+
Enable SMS OTP by setting `otpLogin: true` in your phone login configuration:
7085

71-
{/* */}
86+
```ts title="amplify/auth/resource.ts"
87+
import { defineAuth } from '@aws-amplify/backend';
7288

73-
</InlineFilter>
89+
export const auth = defineAuth({
90+
loginWith: {
91+
phone: {
92+
otpLogin: true
93+
}
94+
}
95+
});
96+
```
7497

7598
<Callout info>
7699

@@ -90,22 +113,21 @@ Email-based authentication uses email addresses for identification and verificat
90113
2. They receive an email message with a time-limited code
91114
3. After the users enters their code they are authenticated
92115

93-
{/* quick blurb of basic usage */}
94-
<InlineFilter filters={["angular", "javascript", "nextjs", "react", "react-native", "vue"]}>
116+
### Configure Email OTP
95117

96-
{/* */}
97-
98-
</InlineFilter>
99-
<InlineFilter filters={["android"]}>
118+
Enable Email OTP by setting `otpLogin: true` in your email login configuration:
100119

101-
{/* */}
102-
103-
</InlineFilter>
104-
<InlineFilter filters={["swift"]}>
105-
106-
{/* */}
120+
```ts title="amplify/auth/resource.ts"
121+
import { defineAuth } from '@aws-amplify/backend';
107122

108-
</InlineFilter>
123+
export const auth = defineAuth({
124+
loginWith: {
125+
email: {
126+
otpLogin: true
127+
}
128+
}
129+
});
130+
```
109131

110132
<Callout info>
111133

@@ -123,12 +145,41 @@ WebAuthn uses biometrics or security keys for authentication, leveraging device-
123145
2. Their device prompts for biometric/security key verification
124146
3. For future logins, they'll authenticate using the same method
125147

126-
{/* quick blurb of basic usage */}
127-
<InlineFilter filters={["angular", "javascript", "nextjs", "react", "react-native", "vue"]}>
148+
### Configure WebAuthn
128149

129-
{/* */}
150+
Enable WebAuthn passkeys in your auth configuration. The simplest configuration uses automatic relying party ID resolution:
151+
152+
```ts title="amplify/auth/resource.ts"
153+
import { defineAuth } from '@aws-amplify/backend';
154+
155+
export const auth = defineAuth({
156+
loginWith: {
157+
email: true, // Users need a sign-up method
158+
webAuthn: true // Automatically resolves relying party ID
159+
}
160+
});
161+
```
162+
163+
When `webAuthn: true` is used, the relying party ID is automatically resolved:
164+
- In **sandbox** environments: resolves to `localhost`
165+
- In **branch** deployments: resolves to your Amplify app domain (e.g., `[branch].[appId].amplifyapp.com`)
166+
167+
For production environments or custom domains, specify the relying party ID explicitly:
168+
169+
```ts title="amplify/auth/resource.ts"
170+
import { defineAuth } from '@aws-amplify/backend';
171+
172+
export const auth = defineAuth({
173+
loginWith: {
174+
email: true,
175+
webAuthn: {
176+
relyingPartyId: 'example.com',
177+
userVerification: 'required' // or 'preferred' (default)
178+
}
179+
}
180+
});
181+
```
130182

131-
</InlineFilter>
132183
<InlineFilter filters={["android"]}>
133184

134185
You can read more about how passkeys work in the [Android developer docs](https://developer.android.com/design/ui/mobile/guides/patterns/passkeys).
@@ -140,7 +191,7 @@ Registering a passkey is supported on Android 9 (API level 28) and above.
140191
Using passkeys with Amplify requires following these steps:
141192

142193
1. Deploy a Digital Asset Links file to your website granting the `get_login_creds` permission to your application. See the [Credential Manager documentation](https://developer.android.com/identity/sign-in/credential-manager#add-support-dal) for more details about this file.
143-
1. [Configure your Amazon Cognito user pool](/[platform]/build-a-backend/auth/modify-resources-with-cdk/#override-cognito-userpool-to-enable-passwordless-sign-in-methods) with `WEB_AUTHN` as an allowed first factor, and specify your website domain as the `WebAuthnRelyingPartyID`.
194+
1. Configure WebAuthn in your `defineAuth` as shown above, specifying your website domain as the `relyingPartyId`.
144195
1. Use the Amplify Android APIs to first [register a passkey](/[platform]/build-a-backend/auth/manage-users/manage-webauthn-credentials/#associate-webauthn-credentials) and then to [sign in with WebAuthn](/[platform]/build-a-backend/auth/connect-your-frontend/sign-in/#webauthn-passkeys).
145196

146197
</InlineFilter>
@@ -157,3 +208,63 @@ Using passkeys with Amplify requires following these steps:
157208
Passwordless authentication with WebAuthn requires associating one or more credentials with the user's Amazon Cognito account. Amplify provides APIs that integrate with each platform's local authenticator to easily create, view, and delete these credential associations.
158209

159210
[Learn more about managing WebAuthn credentials](/[platform]/build-a-backend/auth/manage-users/manage-webauthn-credentials).
211+
212+
## Passwordless authentication
213+
214+
When you enable passwordless authentication methods, traditional password authentication remains available. This gives users flexibility to choose their preferred authentication method:
215+
216+
```ts title="amplify/auth/resource.ts"
217+
import { defineAuth } from '@aws-amplify/backend';
218+
219+
export const auth = defineAuth({
220+
loginWith: {
221+
email: {
222+
otpLogin: true // Email OTP enabled alongside password auth
223+
}
224+
}
225+
});
226+
```
227+
228+
In this configuration, users can authenticate using either:
229+
- Email and password (traditional)
230+
- Email OTP (passwordless)
231+
232+
You can enable multiple passwordless methods to give users even more options:
233+
234+
```ts title="amplify/auth/resource.ts"
235+
import { defineAuth } from '@aws-amplify/backend';
236+
237+
export const auth = defineAuth({
238+
loginWith: {
239+
email: {
240+
otpLogin: true
241+
},
242+
phone: {
243+
otpLogin: true
244+
},
245+
webAuthn: {
246+
relyingPartyId: 'example.com'
247+
}
248+
}
249+
});
250+
```
251+
252+
In this configuration, users can authenticate using:
253+
- Email and password
254+
- Email OTP
255+
- Phone and password
256+
- SMS OTP
257+
- WebAuthn passkeys
258+
259+
<Callout info>
260+
261+
When using WebAuthn, users still need a way to initially sign up (email or phone). WebAuthn credentials are then associated with their account for future sign-ins.
262+
263+
</Callout>
264+
265+
## Next steps
266+
267+
- [Learn how to implement passwordless sign-in in your application](/[platform]/build-a-backend/auth/connect-your-frontend/sign-in/)
268+
- [Configure email settings for Email OTP](/[platform]/build-a-backend/auth/moving-to-production/#email)
269+
- [Configure SMS settings for SMS OTP](/[platform]/build-a-backend/auth/moving-to-production/#sms)
270+
- [Manage WebAuthn credentials](/[platform]/build-a-backend/auth/manage-users/manage-webauthn-credentials/)

src/pages/[platform]/build-a-backend/auth/modify-resources-with-cdk/index.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@ cfnUserPool.policies = {
6565

6666
## Override Cognito UserPool to enable passwordless sign-in methods
6767

68-
You can modify the underlying Cognito user pool resource to enable sign in with passwordless methods. [Learn more about passwordless sign-in methods](/[platform]/build-a-backend/auth/concepts/passwordless/).
68+
<Callout info>
69+
70+
**Recommended approach:** Passwordless authentication can now be configured directly in `defineAuth` without requiring CDK overrides. [Learn how to configure passwordless authentication](/[platform]/build-a-backend/auth/concepts/passwordless/).
71+
72+
</Callout>
73+
74+
For advanced use cases, you can still modify the underlying Cognito user pool resource to enable sign in with passwordless methods using CDK overrides. [Learn more about passwordless sign-in methods](/[platform]/build-a-backend/auth/concepts/passwordless/).
6975

7076
You can also read more about how passwordless authentication flows are implemented in the [Cognito documentation](https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-authentication-flow-methods.html).
7177

src/pages/[platform]/build-a-backend/auth/set-up-auth/index.mdx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,42 @@ export const auth = defineAuth({
4747
})
4848
```
4949

50-
By default, your auth resource is scaffolded using `email` as the default login mechanism. You can also configure your auth resource to allow signing in with phone numbers or an external provider such as Google, Facebook, Amazon, or Sign in with Apple.
50+
By default, your auth resource is scaffolded using `email` as the default login mechanism. You can also configure your auth resource to allow signing in with:
51+
52+
- Phone numbers
53+
- External providers (Google, Facebook, Amazon, or Sign in with Apple)
54+
<InlineFilter filters={['android', 'angular', 'javascript', 'nextjs', 'react', 'react-native', 'swift', 'vue']}>
55+
- [Passwordless authentication](/[platform]/build-a-backend/auth/concepts/passwordless/) (Email OTP, SMS OTP, or WebAuthn passkeys)
56+
</InlineFilter>
5157

5258
<Callout info>
5359

5460
**Note:** At a minimum you will need to pass a `loginWith` value to set up how your users sign in to your app. Signing in with email and password is configured by default if you do not provide any value.
5561

5662
</Callout>
5763

64+
<InlineFilter filters={['android', 'angular', 'javascript', 'nextjs', 'react', 'react-native', 'swift', 'vue']}>
65+
66+
## Enable passwordless authentication
67+
68+
You can enable passwordless authentication methods to provide a more secure and user-friendly experience:
69+
70+
```ts title="amplify/auth/resource.ts"
71+
import { defineAuth } from '@aws-amplify/backend';
72+
73+
export const auth = defineAuth({
74+
loginWith: {
75+
email: {
76+
otpLogin: true // Enable email-based one-time passwords
77+
}
78+
}
79+
});
80+
```
81+
82+
[Learn more about passwordless authentication options](/[platform]/build-a-backend/auth/concepts/passwordless/).
83+
84+
</InlineFilter>
85+
5886
## Deploy auth resource
5987

6088
After you have chosen and defined your authentication resource, run the following command to create your resource in your personal cloud sandbox.

0 commit comments

Comments
 (0)