Skip to content

Commit 5a4a0fb

Browse files
mattcreasertimngyn
andauthored
fix(android): Improve gen 1 TOTP docs (#6877)
* Replace incorrect TOTP fragment with InlineFilter * Add missing Android docs to Sign In Next Steps * Fix indentation in RxJava sample * Use consistent naming for example string * Use InlineFilters to populate correct variable names for Android --------- Co-authored-by: timngyn <timngyn@gmail.com>
1 parent d1573f1 commit 5a4a0fb

File tree

3 files changed

+404
-93
lines changed

3 files changed

+404
-93
lines changed

src/fragments/lib/auth/android/signin_next_steps/91_confirm_totp_mfa.mdx

Lines changed: 0 additions & 91 deletions
This file was deleted.

src/fragments/lib/auth/common/mfa/flows.mdx

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,23 @@ You can use Time-based One-Time Password (TOTP) for multi-factor authentication
219219

220220
### Setting up TOTP for a user
221221

222+
<InlineFilter filters={['android']}>
223+
After you initiate a user sign in with the `signIn` API where a user is required to set up TOTP as an MFA method, the API call will return `CONTINUE_SIGN_IN_WITH_TOTP_SETUP` as a challenge and next step to handle in your app. You will get that challenge if the following conditions are met:
224+
</InlineFilter>
225+
<InlineFilter filters={['swift', 'flutter']}>
222226
After you initiate a user sign in with the `signIn` API where a user is required to set up TOTP as an MFA method, the API call will return `continueSignInWithTOTPSetup` as a challenge and next step to handle in your app. You will get that challenge if the following conditions are met:
227+
</InlineFilter>
223228

224229
- MFA is marked as **Required** in Cognito User Pool.
225230
- TOTP is enabled in the Cognito User Pool
226231
- User does not have TOTP MFA set up already.
227232

233+
<InlineFilter filters={['android']}>
234+
The `CONTINUE_SIGN_IN_WITH_TOTP_SETUP` step signifies that the user must set up TOTP before they can sign in. The step returns an associated value of type `TOTPSetupDetails` which must be used to configure an authenticator app like Microsoft Authenticator or Google Authenticator. `TOTPSetupDetails` provides a helper method called `getSetupURI` which generates a URI that can be used, for example, in a button to open the user's installed authenticator app. For more advanced use cases, `TOTPSetupDetails` also contains a `sharedSecret` which can be used to either generate a QR code or be manually entered into an authenticator app.
235+
</InlineFilter>
236+
<InlineFilter filters={['swift', 'flutter']}>
228237
The `continueSignInWithTOTPSetup` step signifies that the user must set up TOTP before they can sign in. The step returns an associated value of type `TOTPSetupDetails` which must be used to configure an authenticator app like Microsoft Authenticator or Google Authenticator. `TOTPSetupDetails` provides a helper method called `getSetupURI` which generates a URI that can be used, for example, in a button to open the user's installed authenticator app. For more advanced use cases, `TOTPSetupDetails` also contains a `sharedSecret` which can be used to either generate a QR code or be manually entered into an authenticator app.
238+
</InlineFilter>
229239

230240
Once the authenticator app is set up, the user can generate a TOTP code and provide it to the library to complete the sign in process.
231241

@@ -599,15 +609,87 @@ Future<void> updateMfaPreferences() async {
599609

600610
</InlineFilter>
601611

612+
<InlineFilter filters={['android']}>
613+
If multiple MFA methods are enabled for the user, the `signIn` API will return `CONTINUE_SIGN_IN_WITH_MFA_SELECTION` as the next step in the auth flow. During this scenario, the user should be prompted to select the MFA method they want to use to sign in and their preference should be passed to `confirmSignIn`.
614+
</InlineFilter>
615+
<InlineFilter filters={['swift', 'flutter']}>
602616
If multiple MFA methods are enabled for the user, the `signIn` API will return `continueSignInWithMFASelection` as the next step in the auth flow. During this scenario, the user should be prompted to select the MFA method they want to use to sign in and their preference should be passed to `confirmSignIn`.
617+
</InlineFilter>
603618

604619
import iosContinueSignInWithMFASelection from '/src/fragments/lib/auth/ios/signin_next_steps/91_continue_mfa_selection_code.mdx';
605620

606621
<Fragments fragments={{ swift: iosContinueSignInWithMFASelection }} />
607622

608-
import androidContinueSignInWithMFASelection from '/src/fragments/lib/auth/android/signin_next_steps/91_confirm_totp_mfa.mdx';
623+
<InlineFilter filters={['android']}>
624+
625+
<BlockSwitcher>
626+
<Block name="Java">
627+
628+
```java
629+
Amplify.Auth.confirmSignIn(
630+
MFATypeUtil.getChallengeResponse(MFAType.TOTP),
631+
result -> {
632+
if (result.getNextStep().getSignInStep() == AuthSignInStep.CONFIRM_SIGN_IN_WITH_TOTP_CODE) {
633+
Log.i("AuthQuickStart", "Received next step as confirm sign in with TOTP");
634+
}
635+
// ...
636+
},
637+
error -> Log.e("AuthQuickstart", "Confirm sign in failed: " + error)
638+
);
639+
```
640+
641+
</Block>
642+
<Block name="Kotlin - Callbacks">
643+
644+
```kotlin
645+
Amplify.Auth.confirmSignIn(
646+
MFAType.TOTP.challengeResponse,
647+
{ result ->
648+
if (result.nextStep.signInStep == AuthSignInStep.CONFIRM_SIGN_IN_WITH_TOTP_CODE) {
649+
Log.i("AuthQuickStart", "Received next step as confirm sign in with TOTP");
650+
}
651+
// ...
652+
},
653+
{ error -> Log.e("AuthQuickstart", "Confirm sign in failed: $error") }
654+
)
655+
```
656+
657+
</Block>
658+
<Block name="Kotlin - Coroutines">
659+
660+
```kotlin
661+
try {
662+
val result = Amplify.Auth.confirmSignIn(MFAType.TOTP.challengeResponse)
663+
if (result.nextStep.signInStep == AuthSignInStep.CONFIRM_SIGN_IN_WITH_TOTP_CODE) {
664+
Log.i("AuthQuickStart", "Received next step as confirm sign in with TOTP");
665+
}
666+
// ...
667+
} catch(error: Exception) {
668+
Log.e("AuthQuickstart", "Confirm sign in failed: $error")
669+
}
670+
```
609671

610-
<Fragments fragments={{ android: androidContinueSignInWithMFASelection }} />
672+
</Block>
673+
<Block name="RxJava">
674+
675+
```java
676+
RxAmplify.Auth.confirmSignIn(
677+
MFATypeUtil.getChallengeResponse(MFAType.TOTP)
678+
).subscribe(
679+
result -> {
680+
if (result.getNextStep().getSignInStep() == AuthSignInStep.CONFIRM_SIGN_IN_WITH_TOTP_CODE) {
681+
Log.i("AuthQuickStart", "Received next step as confirm sign in with TOTP");
682+
}
683+
// ...
684+
},
685+
error -> Log.e("AuthQuickstart", "Confirm sign in failed: " + error)
686+
);
687+
```
688+
689+
</Block>
690+
</BlockSwitcher>
691+
692+
</InlineFilter>
611693

612694
<InlineFilter filters={['flutter']}>
613695

0 commit comments

Comments
 (0)