Skip to content

Commit bd221aa

Browse files
committed
Add Android's WebAuthn details to connect-your-frontend/sign-in/index.mdx
1 parent 4485e7d commit bd221aa

File tree

1 file changed

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

1 file changed

+124
-23
lines changed

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

Lines changed: 124 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -803,10 +803,10 @@ func confirmSignIn() -> AnyCancellable {
803803

804804
## Sign in with an external identity provider
805805

806-
To sign in using an external identity provider such as Google, use the `signInWithRedirect` function.
807-
808806
<InlineFilter filters={["angular", "javascript", "nextjs", "react", "react-native", "vue"]}>
809807

808+
To sign in using an external identity provider such as Google, use the `signInWithRedirect` function.
809+
810810
```ts
811811
import { signInWithRedirect } from "aws-amplify/auth"
812812

@@ -844,7 +844,10 @@ await autoSignIn();
844844
```
845845

846846
</InlineFilter>
847-
<InlineFilter filters={['react-native']}>
847+
<InlineFilter filters={['react-native']}
848+
>
849+
850+
To sign in using an external identity provider such as Google, use the `signInWithRedirect` function.
848851

849852
### Install native module
850853

@@ -883,6 +886,8 @@ Add the `intent-filter` to your application's main activity, replacing `myapp` w
883886

884887
</InlineFilter>
885888
<InlineFilter filters={['flutter']}>
889+
To sign in using an external identity provider such as Google, use the `signInWithWebUI` function.
890+
886891
### How It Works
887892

888893
Sign-in with web UI will display the sign-in UI inside a webview. After the sign-in process is complete, the sign-in UI will redirect back to your app.
@@ -949,7 +954,10 @@ Future<void> socialSignIn() async {
949954
```
950955
</InlineFilter>
951956
<InlineFilter filters={['android']}>
952-
## Update AndroidManifest.xml
957+
958+
To sign in using an external identity provider such as Google, use the `signInWithSocialWebUI` function.
959+
960+
### Update AndroidManifest.xml
953961

954962
Add the following activity and queries tag to your app's `AndroidManifest.xml` file, replacing `myapp` with
955963
your redirect URI prefix if necessary:
@@ -971,7 +979,7 @@ your redirect URI prefix if necessary:
971979
</application>
972980
```
973981

974-
## Launch Social Web UI Sign In
982+
### Launch Social Web UI Sign In
975983

976984
Sweet! You're now ready to launch sign in with your social provider's web UI.
977985

@@ -1034,7 +1042,10 @@ RxAmplify.Auth.signInWithSocialWebUI(AuthProvider.facebook(), this)
10341042
</InlineFilter>
10351043

10361044
<InlineFilter filters={['swift']}>
1037-
## Update Info.plist
1045+
1046+
To sign in using an external identity provider such as Google, use the `signInWithWebUI` function.
1047+
1048+
### Update Info.plist
10381049

10391050
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.
10401051
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:
@@ -1064,7 +1075,7 @@ You have to enable this in your app's `Info.plist`. Right click Info.plist and t
10641075

10651076
When creating a new SwiftUI app using Xcode 13 no longer require configuration files such as the Info.plist. If you are missing this file, click on the project target, under Info, Url Types, and click '+' to add a new URL Type. Add `myapp` to the URL Schemes. You should see the Info.plist file now with the entry for CFBundleURLSchemes.
10661077

1067-
## Launch Social Web UI Sign In
1078+
### Launch Social Web UI Sign In
10681079

10691080
Invoke the following API with the provider you're using (shown with Facebook below):
10701081

@@ -1140,7 +1151,7 @@ handleNextSignInStep(nextStep);
11401151
</InlineFilter>
11411152
<InlineFilter filters={["android"]}>
11421153

1143-
To request an OTP code via SMS for authentication, you must pass the SMS auth factor type (`AuthFactorType.SMS_OTP`) to the `confirmSignIn` API.
1154+
To request an OTP code via SMS for authentication, you pass the `challengeResponse` for `AuthFactorType.SMS_OTP` to the `confirmSignIn` API.
11441155

11451156
Amplify will respond appropriately to Cognito and return the challenge as the sign in next step: `CONFIRM_SIGN_IN_WITH_OTP_CODE`. You will call `confirmSignIn` again, this time with the OTP that your user provides.
11461157

@@ -1150,7 +1161,7 @@ Amplify will respond appropriately to Cognito and return the challenge as the si
11501161
```java
11511162
// First confirm the challenge type
11521163
Amplify.Auth.confirmSignIn(
1153-
AuthFactorType.SMS_OTP.name(),
1164+
AuthFactorType.SMS_OTP.getChallengeResponse(),
11541165
result -> {
11551166
if (result.getNextStep().getSignInStep() == AuthSignInStep.CONFIRM_SIGN_IN_WITH_OTP) {
11561167
// Show UI to collect OTP
@@ -1175,7 +1186,7 @@ Amplify.Auth.confirmSignIn(
11751186
```kotlin
11761187
// First confirm the challenge type
11771188
Amplify.Auth.confirmSignIn(
1178-
AuthFactorType.SMS_OTP.name,
1189+
AuthFactorType.SMS_OTP.challengeResponse,
11791190
{ result ->
11801191
if (result.nextStep.signInStep == AuthSignInStep.CONFIRM_SIGN_IN_WITH_OTP) {
11811192
// Show UI to collect OTP
@@ -1203,7 +1214,7 @@ Amplify.Auth.confirmSignIn(
12031214

12041215
```kotlin
12051216
// First confirm the challenge type
1206-
var result = Amplify.Auth.confirmSignIn(AuthFactorType.SMS_OTP.name)
1217+
var result = Amplify.Auth.confirmSignIn(AuthFactorType.SMS_OTP.challengeResponse)
12071218
if (result.nextStep.signInStep == AuthSignInStep.CONFIRM_SIGN_IN_WITH_OTP) {
12081219
// Show UI to collect OTP
12091220
}
@@ -1219,7 +1230,7 @@ result = Amplify.Auth.confirmSignIn("123456")
12191230

12201231
```java
12211232
// First confirm the challenge type
1222-
RxAmplify.Auth.confirmSignIn(AuthFactorType.SMS_OTP.name())
1233+
RxAmplify.Auth.confirmSignIn(AuthFactorType.SMS_OTP.getChallengeResponse())
12231234
.subscribe(
12241235
result -> {
12251236
if (result.getNextStep().getSignInStep() == AuthSignInStep.CONFIRM_SIGN_IN_WITH_OTP) {
@@ -1344,7 +1355,7 @@ handleNextSignInStep(nextStep);
13441355
</InlineFilter>
13451356
<InlineFilter filters={["android"]}>
13461357

1347-
To request an OTP code via email for authentication, you must pass the email auth factor type (`AuthFactorType.EMAIL_OTP`) to the `confirmSignIn` API.
1358+
To request an OTP code via email for authentication, you pass the `challengeResponse` for `AuthFactorType.EMAIL_OTP` to the `confirmSignIn` API.
13481359

13491360
Amplify will respond appropriately to Cognito and return the challenge as the sign in next step: `CONFIRM_SIGN_IN_WITH_OTP_CODE`. You will call `confirmSignIn` again, this time with the OTP that your user provides.
13501361

@@ -1354,7 +1365,7 @@ Amplify will respond appropriately to Cognito and return the challenge as the si
13541365
```java
13551366
// First confirm the challenge type
13561367
Amplify.Auth.confirmSignIn(
1357-
AuthFactorType.EMAIL_OTP.name(),
1368+
AuthFactorType.EMAIL_OTP.getChallengeResponse(),
13581369
result -> {
13591370
if (result.getNextStep().getSignInStep() == AuthSignInStep.CONFIRM_SIGN_IN_WITH_OTP) {
13601371
// Show UI to collect OTP
@@ -1379,7 +1390,7 @@ Amplify.Auth.confirmSignIn(
13791390
```kotlin
13801391
// First confirm the challenge type
13811392
Amplify.Auth.confirmSignIn(
1382-
AuthFactorType.EMAIL_OTP.name,
1393+
AuthFactorType.EMAIL_OTP.challengeResponse,
13831394
{ result ->
13841395
if (result.nextStep.signInStep == AuthSignInStep.CONFIRM_SIGN_IN_WITH_OTP) {
13851396
// Show UI to collect OTP
@@ -1407,7 +1418,7 @@ Amplify.Auth.confirmSignIn(
14071418

14081419
```kotlin
14091420
// First confirm the challenge type
1410-
var result = Amplify.Auth.confirmSignIn(AuthFactorType.EMAIL_OTP.name)
1421+
var result = Amplify.Auth.confirmSignIn(AuthFactorType.EMAIL_OTP.challengeResponse)
14111422
if (result.nextStep.signInStep == AuthSignInStep.CONFIRM_SIGN_IN_WITH_OTP) {
14121423
// Show UI to collect OTP
14131424
}
@@ -1423,7 +1434,7 @@ result = Amplify.Auth.confirmSignIn("123456")
14231434

14241435
```java
14251436
// First confirm the challenge type
1426-
RxAmplify.Auth.confirmSignIn(AuthFactorType.EMAIL_OTP.name())
1437+
RxAmplify.Auth.confirmSignIn(AuthFactorType.EMAIL_OTP.getChallengeResponse())
14271438
.subscribe(
14281439
result -> {
14291440
if (result.getNextStep().getSignInStep() == AuthSignInStep.CONFIRM_SIGN_IN_WITH_OTP) {
@@ -1547,7 +1558,97 @@ handleNextSignInStep(nextStep);
15471558
</InlineFilter>
15481559
<InlineFilter filters={["android"]}>
15491560

1550-
{/* */}
1561+
To sign in with WebAuthn, you pass the `challengeResponse` for `AuthFactorType.WEB_AUTHN` to the `confirmSignIn` API. Amplify will invoke Android's Credential Manager to retrieve a PassKey, and the user will be shown a system UI to authorize the PassKey access. This flow
1562+
completes without any additional interaction from your application, so there is only one `confirmSignIn` call needed for WebAuthn.
1563+
1564+
<Callout>
1565+
Amplify requires an `Activity` reference to attach the PassKey UI to your Application's [Task](https://developer.android.com/guide/components/activities/tasks-and-back-stack) when using WebAuthn - if an `Activity` is not supplied then the UI will appear in a separate Task. For this reason, we strongly recommend passing the `callingActivity` option to both the `signIn` and `confirmSignIn` APIs if your application uses the `USER_AUTH` flow.
1566+
</Callout>
1567+
1568+
<BlockSwitcher>
1569+
<Block name="Java">
1570+
1571+
```java
1572+
// Pass the calling activity
1573+
AuthSignInOptions options = AWSCognitoAuthConfirmSignInOptions.builder()
1574+
.callingActivity(activity)
1575+
.build();
1576+
1577+
// Confirm WebAuthn as the challenge type
1578+
Amplify.Auth.confirmSignIn(
1579+
AuthFactorType.WEB_AUTHN.getChallengeResponse(),
1580+
options,
1581+
result -> Log.i("AuthQuickStart", "Next sign in step: " + result.getNextStep()),
1582+
error -> Log.e("AuthQuickstart", "Failed to sign in", error)
1583+
);
1584+
```
1585+
1586+
</Block>
1587+
<Block name="Kotlin - Callbacks">
1588+
1589+
```kotlin
1590+
// Pass the calling activity
1591+
val options = AWSCognitoAuthConfirmSignInOptions.builder()
1592+
.callingActivity(activity)
1593+
.build()
1594+
1595+
// Confirm WebAuthn as the challenge type
1596+
Amplify.Auth.confirmSignIn(
1597+
AuthFactorType.WEB_AUTHN.name,
1598+
options,
1599+
{ result -> Log.i("AuthQuickStart", "Next sign in step: ${result.nextStep}") },
1600+
{ error -> Log.i("AuthQuickstart", "Failed to sign in", error) }
1601+
)
1602+
```
1603+
1604+
</Block>
1605+
<Block name="Kotlin - Coroutines">
1606+
1607+
```kotlin
1608+
// Pass the calling activity
1609+
val options = AWSCognitoAuthConfirmSignInOptions.builder()
1610+
.callingActivity(activity)
1611+
.build()
1612+
1613+
try {
1614+
// Confirm WebAuthn as the challenge type
1615+
var result = Amplify.Auth.confirmSignIn(
1616+
challengeResponse = AuthFactorType.WEB_AUTHN.challengeResponse,
1617+
options = options
1618+
)
1619+
Log.i("AuthQuickStart", "Next sign in step: ${result.nextStep}")
1620+
} catch (error: AuthException) {
1621+
Log.e("AuthQuickstart", "Failed to sign in", error)
1622+
}
1623+
```
1624+
1625+
</Block>
1626+
<Block name="RxJava">
1627+
1628+
```java
1629+
// Pass the calling activity
1630+
AuthSignInOptions options = AWSCognitoAuthConfirmSignInOptions.builder()
1631+
.callingActivity(activity)
1632+
.build();
1633+
1634+
// Confirm WebAuthn as the challenge type
1635+
RxAmplify.Auth.confirmSignIn(AuthFactorType.WEB_AUTHN.getChallengeResponse(), options)
1636+
.subscribe(
1637+
result -> Log.i("AuthQuickStart", "Next sign in step: " + result.getNextStep()),
1638+
error -> Log.e("AuthQuickstart", "Failed to sign in", error)
1639+
);
1640+
```
1641+
1642+
</Block>
1643+
</BlockSwitcher>
1644+
1645+
Using WebAuthn sign in may result in a number of possible exception types.
1646+
1647+
- `UserCancelledException` - If the user declines to authorize access to the PassKey in the system UI. You can retry the WebAuthn flow by invoking `confirmSignIn` again, or restart the `signIn` process to select a different `AuthFactorType`.
1648+
- `WebAuthnNotEnabledException` - This indicates WebAuthn is not enabled in your user pool.
1649+
- `WebAuthnNotSupportedException` - This indicates WebAuthn is not supported on the user's device.
1650+
- `WebAuthnRpMismatchException` - This indicates there is a problem with the `assetlinks.json` file deployed to your relying party.
1651+
- `WebAuthnFailedException` - This exception is used for other errors that may occur with WebAuthn. Inspect the `cause` to determine the best course of action.
15511652

15521653
</InlineFilter>
15531654
<InlineFilter filters={["flutter"]}>
@@ -1565,7 +1666,7 @@ handleNextSignInStep(nextStep);
15651666

15661667
### Password or SRP
15671668

1568-
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.
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.
15691670

15701671
</InlineFilter>
15711672

@@ -1596,7 +1697,7 @@ handleNextSignInStep(nextNextStep);
15961697
```java
15971698
// First confirm the challenge type
15981699
Amplify.Auth.confirmSignIn(
1599-
AuthFactorType.PASSWORD, // or PASSWORD_SRP
1700+
AuthFactorType.PASSWORD.getChallengeResponse(), // or PASSWORD_SRP
16001701
result -> {
16011702
if (result.getNextStep().getSignInStep() == AuthSignInStep.CONFIRM_SIGN_IN_WITH_PASSWORD) {
16021703
// Show UI to collect password
@@ -1621,7 +1722,7 @@ Amplify.Auth.confirmSignIn(
16211722
```kotlin
16221723
// First confirm the challenge type
16231724
Amplify.Auth.confirmSignIn(
1624-
AuthFactorType.PASSWORD.name, // or PASSWORD_SRP
1725+
AuthFactorType.PASSWORD.challengeResponse, // or PASSWORD_SRP
16251726
{ result ->
16261727
if (result.nextStep.signInStep == AuthSignInStep.CONFIRM_SIGN_IN_WITH_PASSWORD) {
16271728
// Show UI to collect password
@@ -1649,7 +1750,7 @@ Amplify.Auth.confirmSignIn(
16491750

16501751
```kotlin
16511752
// First confirm the challenge type
1652-
var result = Amplify.Auth.confirmSignIn(AuthFactorType.PASSWORD.name) // or PASSWORD_SRP
1753+
var result = Amplify.Auth.confirmSignIn(AuthFactorType.PASSWORD.challengeResponse) // or PASSWORD_SRP
16531754
if (result.nextStep.signInStep == AuthSignInStep.CONFIRM_SIGN_IN_WITH_PASSWORD) {
16541755
// Show UI to collect password
16551756
}
@@ -1665,7 +1766,7 @@ result = Amplify.Auth.confirmSignIn("password")
16651766

16661767
```java
16671768
// First confirm the challenge type
1668-
RxAmplify.Auth.confirmSignIn(AuthFactorType.PASSWORD.name()) // or PASSWORD_SRP
1769+
RxAmplify.Auth.confirmSignIn(AuthFactorType.PASSWORD.getChallengeResponse()) // or PASSWORD_SRP
16691770
.subscribe(
16701771
result -> {
16711772
if (result.getNextStep().getSignInStep() == AuthSignInStep.CONFIRM_SIGN_IN_WITH_PASSWORD) {

0 commit comments

Comments
 (0)