サインイン
Amplify は、Amplify Auth などのバックエンドリソースと対話できるクライアントライブラリを提供しています。
signIn API の使用
Amplify.Auth.signIn( "username", "password", result -> Log.i("AuthQuickstart", result.isSignedIn() ? "Sign in succeeded" : "Sign in not complete"), error -> Log.e("AuthQuickstart", error.toString()));Amplify.Auth.signIn("username", "password", { result -> if (result.isSignedIn) { Log.i("AuthQuickstart", "Sign in succeeded") } else { Log.i("AuthQuickstart", "Sign in not complete") } }, { Log.e("AuthQuickstart", "Failed to sign in", it) })try { val result = Amplify.Auth.signIn("username", "password") if (result.isSignedIn) { Log.i("AuthQuickstart", "Sign in succeeded") } else { Log.e("AuthQuickstart", "Sign in not complete") }} catch (error: AuthException) { Log.e("AuthQuickstart", "Sign in failed", error)}RxAmplify.Auth.signIn("username", "password") .subscribe( result -> Log.i("AuthQuickstart", result.isSignedIn() ? "Sign in succeeded" : "Sign in not complete"), error -> Log.e("AuthQuickstart", error.toString()) );signIn API のレスポンスには nextStep プロパティが含まれており、さらなるアクションが必要かどうかを判断するために使用できます。次のステップが返される可能性があります:
| 次のステップ | 説明 |
|---|---|
CONFIRM_SIGN_IN_WITH_NEW_PASSWORD | ユーザーは一時パスワードで作成されており、新しいパスワードを設定する必要があります。confirmSignIn でプロセスを完了してください。 |
CONFIRM_SIGN_IN_WITH_CUSTOM_CHALLENGE | サインインはカスタムチャレンジレスポンスで確認する必要があります。confirmSignIn でプロセスを完了してください。 |
CONFIRM_SIGN_IN_WITH_TOTP_CODE | サインインはユーザーからの TOTP コードで確認する必要があります。confirmSignIn でプロセスを完了してください。 |
CONFIRM_SIGN_IN_WITH_SMS_MFA_CODE | サインインはユーザーからの SMS コードで確認する必要があります。confirmSignIn でプロセスを完了してください。 |
CONFIRM_SIGN_IN_WITH_OTP | サインインはユーザーからのコード(SMS またはメールで送信)で確認する必要があります。confirmSignIn でプロセスを完了してください。 |
CONFIRM_SIGN_IN_WITH_PASSWORD | サインインはユーザーからのパスワードで確認する必要があります。confirmSignIn でプロセスを完了してください。 |
CONTINUE_SIGN_IN_WITH_MFA_SETUP_SELECTION | ユーザーはセットアップする MFA 確認のモードを選択する必要があります。confirmSignIn に MFAType.EMAIL.challengeResponse または MFAType.TOTP.challengeResponse を渡してプロセスを完了してください。 |
CONTINUE_SIGN_IN_WITH_MFA_SELECTION | ユーザーはサインイン前に MFA 確認のモードを選択する必要があります。confirmSignIn でプロセスを完了してください。 |
CONTINUE_SIGN_IN_WITH_TOTP_SETUP | TOTP セットアッププロセスを続行する必要があります。confirmSignIn でプロセスを完了してください。 |
CONTINUE_SIGN_IN_WITH_EMAIL_MFA_SETUP | EMAIL セットアッププロセスを続行する必要があります。有効なメールアドレスを confirmSignIn に渡してプロセスを完了してください。 |
CONTINUE_SIGN_IN_WITH_FIRST_FACTOR_SELECTION | ユーザーは最初の要素認証のモードを選択する必要があります。confirmSignIn の challengeResponse フィールドに希望するモードを渡してプロセスを完了してください。 |
RESET_PASSWORD | ユーザーは resetPassword を使用してパスワードをリセットする必要があります。 |
CONFIRM_SIGN_UP | ユーザーはサインアップフローを完全に完了しておらず、confirmSignUp で確認する必要があります。 |
DONE | サインインプロセスが完了しました。 |
返される可能性がある MFA ステップの処理の詳細については、多要素認証を参照してください。
多要素認証が有効な場合
メールまたは SMS MFA が有効になっている場合、Cognito はユーザーに代わってメッセージを送信します。メールメッセージと SMS メッセージは、ユーザーがそれぞれメールアドレスと電話番号の属性を持っている必要があります。メール MFA または SMS MFA を使用する場合は、これらの属性をユーザープールで必須に設定することをお勧めします。これらの属性が必須の場合、ユーザーはサインアッププロセスを完了する前にこれらの情報を提供する必要があります。
MFA を必須に設定し、複数の認証要素を有効にした場合、Cognito は新しいユーザーに使用する MFA 要素を選択するよう促します。SMS を選択するには電話番号が必要で、メール MFA を選択するにはメールアドレスが必要です。
利用可能なメッセージベースの MFA に必要な属性が定義されていないユーザーがいる場合、Cognito は TOTP のセットアップを促します。
バックエンド認証リソースで MFA を有効にする方法の詳細については、多要素認証のドキュメントを参照してください。
ArrayList<AuthUserAttribute> attributes = new ArrayList<>();attributes.add(new AuthUserAttribute(AuthUserAttributeKey.email(), "my@email.com"));attributes.add(new AuthUserAttribute(AuthUserAttributeKey.phoneNumber(), "+15551234567"));
Amplify.Auth.signUp( "username", "Password123", AuthSignUpOptions.builder().userAttributes(attributes).build(), result -> Log.i("AuthQuickstart", result.toString()), error -> Log.e("AuthQuickstart", error.toString()));val attrs = mapOf( AuthUserAttributeKey.email() to "my@email.com", AuthUserAttributeKey.phoneNumber() to "+15551234567")val options = AuthSignUpOptions.builder() .userAttributes(attrs.map { AuthUserAttribute(it.key, it.value) }) .build()Amplify.Auth.signUp("username", "Password123", options, { Log.i("AuthQuickstart", "Sign up result = $it") }, { Log.e("AuthQuickstart", "Sign up failed", it) })val attrs = mapOf( AuthUserAttributeKey.email() to "my@email.com", AuthUserAttributeKey.phoneNumber() to "+15551234567")val options = AuthSignUpOptions.builder() .userAttributes(attrs.map { AuthUserAttribute(it.key, it.value) }) .build()try { val result = Amplify.Auth.signUp("username", "Password123", options) Log.i("AuthQuickstart", "Sign up OK: $result")} catch (error: AuthException) { Log.e("AuthQuickstart", "Sign up failed", error)}ArrayList<AuthUserAttribute> attributes = new ArrayList<>();attributes.add(new AuthUserAttribute(AuthUserAttributeKey.email(), "my@email.com"));attributes.add(new AuthUserAttribute(AuthUserAttributeKey.phoneNumber(), "+15551234567"));
RxAmplify.Auth.signUp( "username", "Password123", AuthSignUpOptions.builder().userAttributes(attributes).build()) .subscribe( result -> Log.i("AuthQuickstart", result.toString()), error -> Log.e("AuthQuickstart", error.toString()) );サインインの確認
サインイン後、次のいずれかのタイプの nextStep がサインイン結果として返されます。ユーザーのレスポンスを収集し、confirmSignIn API に渡してサインインフローを完了してください。
| 次のステップ | 説明 |
|---|---|
CONFIRM_SIGN_IN_WITH_TOTP_CODE | サインインはユーザーからの TOTP コードで確認する必要があります。confirmSignIn でプロセスを完了してください。 |
CONFIRM_SIGN_IN_WITH_SMS_MFA_CODE | サインインはユーザーからの SMS コードで確認する必要があります。confirmSignIn でプロセスを完了してください。 |
CONFIRM_SIGN_IN_WITH_OTP | サインインはユーザーからのコード(SMS またはメールで送信)で確認する必要があります。confirmSignIn でプロセスを完了してください。 |
CONFIRM_SIGN_IN_WITH_PASSWORD | サインインはユーザーからのパスワードで確認する必要があります。confirmSignIn でプロセスを完了してください。 |
CONTINUE_SIGN_IN_WITH_FIRST_FACTOR_SELECTION | ユーザーは最初の要素認証のモードを選択する必要があります。confirmSignIn の challengeResponse フィールドに希望するモードを渡してプロセスを完了してください。 |
CONTINUE_SIGN_IN_WITH_MFA_SELECTION | ユーザーはサインイン前に MFA 確認のモードを選択する必要があります。confirmSignIn でプロセスを完了してください。 |
CONTINUE_SIGN_IN_WITH_MFA_SETUP_SELECTION | ユーザーはセットアップする MFA 確認のモードを選択する必要があります。confirmSignIn に MFAType.EMAIL.challengeResponse または MFAType.TOTP.challengeResponse を渡してプロセスを完了してください。 |
CONTINUE_SIGN_IN_WITH_TOTP_SETUP | TOTP セットアッププロセスを続行する必要があります。confirmSignIn でプロセスを完了してください。 |
CONTINUE_SIGN_IN_WITH_EMAIL_MFA_SETUP | EMAIL セットアッププロセスを続行する必要があります。有効なメールアドレスを confirmSignIn に渡してプロセスを完了してください。 |
Amplify.Auth.confirmSignIn( "confirmation code received via SMS", result -> Log.i("AuthQuickstart", result.toString()), error -> Log.e("AuthQuickstart", error.toString()));Amplify.Auth.confirmSignIn("code received via SMS", { Log.i("AuthQuickstart", "Confirmed signin: $it") }, { Log.e("AuthQuickstart", "Failed to confirm signin", it) })try { val result = Amplify.Auth.confirmSignIn("code received via SMS") Log.i("AuthQuickstart", "Confirmed signin: $result")} catch (error: AuthException) { Log.e("AuthQuickstart", "Failed to confirm signin", error)}RxAmplify.Auth.confirmSignIn("confirmation code received via SMS") .subscribe( result -> Log.i("AuthQuickstart", result.toString()), error -> Log.e("AuthQuickstart", error.toString()) );外部 ID プロバイダーでサインイン
Google などの外部 ID プロバイダーを使用してサインインするには、signInWithSocialWebUI 関数を使用します。
AndroidManifest.xml の更新
アプリの AndroidManifest.xml ファイルに以下のアクティビティとクエリタグを追加してください。必要に応じて myapp をリダイレクト URI プレフィックスに置き換えてください:
<application ...> ... <activity android:name="com.amplifyframework.auth.cognito.activities.HostedUIRedirectActivity" android:exported="true"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="myapp" /> </intent-filter> </activity> ...</application>ソーシャル Web UI サインインの起動
これで、ソーシャルプロバイダーの Web UI でサインインを起動する準備ができました。
今は、使用しているプロバイダーを指定して(以下は Facebook を使用した例)、このメソッドを MainActivity の onCreate メソッドに追加してください:
// Replace facebook with your chosen auth provider such as google, amazon, or appleAmplify.Auth.signInWithSocialWebUI( AuthProvider.facebook(), this, result -> Log.i("AuthQuickstart", result.toString()), error -> Log.e("AuthQuickstart", error.toString()));// Replace facebook with your chosen auth provider such as google, amazon, or appleAmplify.Auth.signInWithSocialWebUI( AuthProvider.facebook(), this, { Log.i("AuthQuickstart", "Sign in OK: $it") }, { Log.e("AuthQuickstart", "Sign in failed", it) })try { // Replace facebook with your chosen auth provider such as google, amazon, or apple val result = Amplify.Auth.signInWithSocialWebUI(AuthProvider.facebook(), this) Log.i("AuthQuickstart", "Sign in OK: $result")} catch (error: AuthException) { Log.e("AuthQuickstart", "Sign in failed", error)}// Replace facebook with your chosen auth provider such as google, amazon, or appleRxAmplify.Auth.signInWithSocialWebUI(AuthProvider.facebook(), this) .subscribe( result -> Log.i("AuthQuickstart", result.toString()), error -> Log.e("AuthQuickstart", error.toString()) );パスワードレス方式でサインイン
アプリケーションのユーザーはパスワードレス方式でサインインすることもできます。さまざまなパスワードレス認証フローのセットアップ方法を含む詳細については、パスワードレスのコンセプトページを参照してください。
SMS OTP
SMS OTP を使用したパスワードレス認証フローを開始するには、signIn API を呼び出す際に preferredFirstFactor として SMS_OTP を渡します。
// Use options to specify the preferred first factorAWSCognitoAuthSignInOptions options = AWSCognitoAuthSignInOptions.builder() .authFlowType(AuthFlowType.USER_AUTH) .preferredFirstFactor(AuthFactorType.SMS_OTP) // Sign in using SMS OTP .build();
// Sign in the userAmplify.Auth.signIn( username, null, // no password options, result -> { if (result.getNextStep().getSignInStep() == AuthSignInStep.CONFIRM_SIGN_IN_WITH_OTP) { // Show UI to collect OTP } }, error -> Log.e("AuthQuickstart", error.toString()));
// Then pass that OTP into the confirmSignIn APIAmplify.Auth.confirmSignIn( "123456", result -> { // result.getNextStep().getSignInStep() should be "DONE" now }, error -> Log.e("AuthQuickstart", error.toString()));// Use options to specify the preferred first factorval options = AWSCognitoAuthSignInOptions.builder() .authFlowType(AuthFlowType.USER_AUTH) .preferredFirstFactor(AuthFactorType.SMS_OTP) // Sign in using SMS OTP .build()
// Sign in the userAmplify.Auth.signIn( username, null, // no password options, { result: AuthSignInResult -> if (result.nextStep.signInStep == AuthSignInStep.CONFIRM_SIGN_IN_WITH_OTP) { // Show UI to collect OTP } }, { error: AuthException -> Log.e("AuthQuickstart", error.toString()) })
// Then pass that OTP into the confirmSignIn APIAmplify.Auth.confirmSignIn( "123456", { result: AuthSignInResult? -> }, { error: AuthException -> Log.e("AuthQuickstart", error.toString()) })// Use options to specify the preferred first factorval options = AWSCognitoAuthSignInOptions.builder() .authFlowType(AuthFlowType.USER_AUTH) .preferredFirstFactor(AuthFactorType.SMS_OTP) // Sign in using SMS OTP .build()
// Sign in the userval result = Amplify.Auth.signIn( username = username, password = null, options = options)if (result.nextStep.signInStep == AuthSignInStep.CONFIRM_SIGN_IN_WITH_OTP) { // Show UI to collect OTP}
// Then pass that OTP into the confirmSignIn APIval confirmResult = Amplify.Auth.confirmSignIn( challengeResponse = "123456")// confirmResult.nextStep.signInStep should be "DONE"// Use options to specify the preferred first factorAWSCognitoAuthSignInOptions options = AWSCognitoAuthSignInOptions.builder() .authFlowType(AuthFlowType.USER_AUTH) .preferredFirstFactor(AuthFactorType.SMS_OTP) // Sign in using SMS OTP .build();
// Sign in the userRxAmplify.Auth.signIn( username, null, // no password options).subscribe( result -> { if (result.getNextStep().getSignInStep() == AuthSignInStep.CONFIRM_SIGN_IN_WITH_OTP) { // Show UI to collect OTP } }, error -> Log.e("AuthQuickstart", error.toString()))
// Then pass that OTP into the confirmSignIn APIRxAmplify.Auth.confirmSignIn("123456") .subscribe( result -> { // result.getNextStep().getSignInStep() should be "DONE" now }, error -> Log.e("AuthQuickstart", error.toString()) );Email OTP
Email OTP を使用したパスワードレス認証フローを開始するには、signIn API を呼び出す際に preferredFirstFactor として EMAIL_OTP を渡します。
// Use options to specify the preferred first factorAWSCognitoAuthSignInOptions options = AWSCognitoAuthSignInOptions.builder() .authFlowType(AuthFlowType.USER_AUTH) .preferredFirstFactor(AuthFactorType.EMAIL_OTP) // Sign in using Email OTP .build();
// Sign in the userAmplify.Auth.signIn( username, null, // no password options, result -> { if (result.getNextStep().getSignInStep() == AuthSignInStep.CONFIRM_SIGN_IN_WITH_OTP) { // Show UI to collect OTP } }, error -> Log.e("AuthQuickstart", error.toString()));
// Then pass that OTP into the confirmSignIn APIAmplify.Auth.confirmSignIn( "123456", result -> { // result.getNextStep().getSignInStep() should be "DONE" now }, error -> Log.e("AuthQuickstart", error.toString()));// Use options to specify the preferred first factorval options = AWSCognitoAuthSignInOptions.builder() .authFlowType(AuthFlowType.USER_AUTH) .preferredFirstFactor(AuthFactorType.EMAIL_OTP) // Sign in using Email OTP .build()
// Sign in the userAmplify.Auth.signIn( username, null, // no password options, { result: AuthSignInResult -> if (result.nextStep.signInStep == AuthSignInStep.CONFIRM_SIGN_IN_WITH_OTP) { // Show UI to collect OTP } }, { error: AuthException -> Log.e("AuthQuickstart", error.toString()) })
// Then pass that OTP into the confirmSignIn APIAmplify.Auth.confirmSignIn( "123456", { result: AuthSignInResult? -> }, { error: AuthException -> Log.e("AuthQuickstart", error.toString()) })// Use options to specify the preferred first factorval options = AWSCognitoAuthSignInOptions.builder() .authFlowType(AuthFlowType.USER_AUTH) .preferredFirstFactor(AuthFactorType.EMAIL_OTP) // Sign in using Email OTP .build()
// Sign in the userval result = Amplify.Auth.signIn( username = username, password = null, options = options)if (result.nextStep.signInStep == AuthSignInStep.CONFIRM_SIGN_IN_WITH_OTP) { // Show UI to collect OTP}
// Then pass that OTP into the confirmSignIn APIval confirmResult = Amplify.Auth.confirmSignIn( challengeResponse = "123456")// confirmResult.nextStep.signInStep should be "DONE"// Use options to specify the preferred first factorAWSCognitoAuthSignInOptions options = AWSCognitoAuthSignInOptions.builder() .authFlowType(AuthFlowType.USER_AUTH) .preferredFirstFactor(AuthFactorType.EMAIL_OTP) // Sign in using Email OTP .build();
// Sign in the userRxAmplify.Auth.signIn( username, null, // no password options).subscribe( result -> { if (result.getNextStep().getSignInStep() == AuthSignInStep.CONFIRM_SIGN_IN_WITH_OTP) { // Show UI to collect OTP } }, error -> Log.e("AuthQuickstart", error.toString()))
// Then pass that OTP into the confirmSignIn APIRxAmplify.Auth.confirmSignIn("123456") .subscribe( result -> { // result.getNextStep().getSignInStep() should be "DONE" now }, error -> Log.e("AuthQuickstart", error.toString()) );WebAuthn パスキー
WebAuthn 認証情報を使用したパスワードレス認証フローを開始するには、WEB_AUTHN を preferredFirstFactor として渡します。このフローは
アプリケーションからの追加のインタラクションなしに完了するため、WebAuthn には 1 つの Amplify.Auth 呼び出しのみが必要です。
// Use options to specify the preferred first factorAWSCognitoAuthSignInOptions options = AWSCognitoAuthSignInOptions.builder() .authFlowType(AuthFlowType.USER_AUTH) .callingActivity(callingActivity) .preferredFirstFactor(AuthFactorType.WEB_AUTHN) // Sign in using WebAuthn .build();
// Sign in the userAmplify.Auth.signIn( username, null, // no password options, result -> Log.i("AuthQuickStart", "Next sign in step: " + result.getNextStep()), error -> Log.e("AuthQuickstart", error.toString()));// Use options to specify the preferred first factorval options = AWSCognitoAuthSignInOptions.builder() .authFlowType(AuthFlowType.USER_AUTH) .callingActivity(callingActivity) .preferredFirstFactor(AuthFactorType.WEB_AUTHN) // Sign in using WebAuthn .build()
// Sign in the userAmplify.Auth.signIn( username, null, // no password options, { result: AuthSignInResult -> Log.i("AuthQuickStart", "Next sign in step: ${result.nextStep}") }, { error: AuthException -> Log.e("AuthQuickStart", error.toString()) })// Use options to specify the preferred first factorval options = AWSCognitoAuthSignInOptions.builder() .authFlowType(AuthFlowType.USER_AUTH) .callingActivity(callingActivity) .preferredFirstFactor(AuthFactorType.WEB_AUTHN) // Sign in using WebAuthn .build()
// Sign in the userval result = Amplify.Auth.signIn( username = username, password = null, options = options)
// result.nextStep.signInStep should be "DONE" if use granted access to the passkey// NOTE: `signIn` will throw a UserCancelledException if user dismissed the passkey UI// Use options to specify the preferred first factorAWSCognitoAuthSignInOptions options = AWSCognitoAuthSignInOptions.builder() .authFlowType(AuthFlowType.USER_AUTH) .callingActivity(callingActivity) .preferredFirstFactor(AuthFactorType.WEB_AUTHN) // Sign in using WebAuthn .build();
// Sign in the userRxAmplify.Auth.signIn( username, null, // no password options).subscribe( result -> Log.i("AuthQuickStart", "Next sign in step: " + result.getNextStep()), error -> Log.e("AuthQuickstart", error.toString()))WebAuthn サインインを使用すると、いくつかの例外タイプが発生する可能性があります。
UserCancelledException- ユーザーがシステム UI でパスキーへのアクセス認可を拒否した場合。confirmSignInを再度呼び出して WebAuthn フローを再試行するか、signInプロセスを再起動して別のAuthFactorTypeを選択できます。WebAuthnNotEnabledException- これはユーザープールで WebAuthn が有効になっていないことを示します。WebAuthnNotSupportedException- これはユーザーのデバイスで WebAuthn がサポートされていないことを示します。WebAuthnRpMismatchException- これはリライングパーティにデプロイされたassetlinks.jsonファイルに問題があることを示します。WebAuthnFailedException- この例外は WebAuthn で発生する可能性のある他のエラーに使用されます。最善の対処方法を判断するためにcauseを調査してください。
パスワード
従来のパスワードベースの認証フローを開始するには、preferredFirstFactor として PASSWORD または PASSWORD_SRP を渡します。
// Use options to specify the preferred first factorAWSCognitoAuthSignInOptions options = AWSCognitoAuthSignInOptions.builder() .authFlowType(AuthFlowType.USER_AUTH) .preferredFirstFactor(AuthFactorType.PASSWORD) // Sign in using Password .build();
// Sign in the userAmplify.Auth.signIn( username, password, // supply the password if preferredFirstFactor is PASSWORD or PASSWORD_SRP options, result -> Log.i("AuthQuickStart", "Next sign in step: " + result.getNextStep()), error -> Log.e("AuthQuickstart", error.toString()));// Use options to specify the preferred first factorval options = AWSCognitoAuthSignInOptions.builder() .authFlowType(AuthFlowType.USER_AUTH) .preferredFirstFactor(AuthFactorType.PASSWORD) // Sign in using Password .build()
// Sign in the userAmplify.Auth.signIn( username, password, // supply the password if preferredFirstFactor is PASSWORD or PASSWORD_SRP options, { result: AuthSignInResult -> Log.i("AuthQuickStart", "Next sign in step: ${result.nextStep}") }, { error: AuthException -> Log.e("AuthQuickstart", error.toString()) })// Use options to specify the preferred first factorval options = AWSCognitoAuthSignInOptions.builder() .authFlowType(AuthFlowType.USER_AUTH) .preferredFirstFactor(AuthFactorType.PASSWORD) // Sign in using Password .build()
// Sign in the userval result = Amplify.Auth.signIn( username = username, password = password, // supply the password if preferredFirstFactor is PASSWORD or PASSWORD_SRP options = options)
// result.nextStep.signInStep should be "DONE"// Use options to specify the preferred first factorAWSCognitoAuthSignInOptions options = AWSCognitoAuthSignInOptions.builder() .authFlowType(AuthFlowType.USER_AUTH) .preferredFirstFactor(AuthFactorType.Password) // Sign in using Password .build();
// Sign in the userRxAmplify.Auth.signIn( username, password, // supply the password if preferredFirstFactor is PASSWORD or PASSWORD_SRP options).subscribe( result -> Log.i("AuthQuickStart", "Next sign in step: " + result.getNextStep()), error -> Log.e("AuthQuickstart", error.toString()))第一要素の選択
preferredFirstFactor オプションを省略して、特定のユーザーに利用可能な第一要素を検出します。これは、ユーザーがサインイン方法を選択できるようにするのに役立ちます。
その後、confirmSignIn API を使用してチャレンジを選択し、関連する認証フローを開始できます。
// Omit preferredFirstFactor. If the user has more than one factor available then// the next step will be CONTINUE_SIGN_IN_WITH_FIRST_FACTOR_SELECTION.AuthSignInOptions options = AWSCognitoAuthSignInOptions.builder() .authFlowType(AuthFlowType.USER_AUTH) .build();
// Step 1: Sign in the userAmplify.Auth.signIn( "hello@example.com", null, options, result -> { if (result.getNextStep().getSignInStep() == AuthSignInStep.CONTINUE_SIGN_IN_WITH_FIRST_FACTOR_SELECTION) { Log.i( "AuthQuickstart", "Available authentication factors for this user: " + result.getNextStep().getAvailableFactors() ); } }, error -> Log.e("AuthQuickstart", error.toString()));
// Step 2: Select SMS OTP for sign inAmplify.Auth.confirmSignIn( AuthFactorType.SMS_OTP.getChallengeResponse(), result -> { if (result.getNextStep().getSignInStep() == AuthSignInStep.CONFIRM_SIGN_IN_WITH_OTP) { Log.i( "AuthQuickStart", "OTP code sent to " + result.getNextStep().getCodeDeliveryDetails() ) // Show UI to collect OTP } }, error -> Log.e("AuthQuickstart", error.toString()));
// Step 3: Then pass that OTP into the confirmSignIn APIAmplify.Auth.confirmSignIn( "123456", result -> { // result.getNextStep().getSignInStep() should be "DONE" now }, error -> Log.e("AuthQuickstart", error.toString()));// Omit preferredFirstFactor. If the user has more than one factor available then// the next step will be CONTINUE_SIGN_IN_WITH_FIRST_FACTOR_SELECTION.val options: AuthSignInOptions = AWSCognitoAuthSignInOptions.builder() .authFlowType(AuthFlowType.USER_AUTH) .build()
// Step 1: Sign in the userAmplify.Auth.signIn( "hello@example.com", null, options, { result: AuthSignInResult -> if (result.nextStep.signInStep == AuthSignInStep.CONTINUE_SIGN_IN_WITH_FIRST_FACTOR_SELECTION) { Log.i( "AuthQuickstart", "Available authentication factors for this user: ${result.nextStep.availableFactors}" ) } }, { error: AuthException -> Log.e("AuthQuickstart", error.toString()) })
// Step 2: Select SMS OTP for sign inAmplify.Auth.confirmSignIn( AuthFactorType.SMS_OTP.getChallengeResponse(), { result: AuthSignInResult -> if (result.nextStep.signInStep == AuthSignInStep.CONFIRM_SIGN_IN_WITH_OTP) { Log.i( "AuthQuickStart", "OTP code sent to ${result.nextStep.codeDeliveryDetails}" ) // Show UI to collect OTP } }, { error: AuthException -> Log.e("AuthQuickstart", error.toString()) })
// Step 3: Then pass that OTP into the confirmSignIn APIAmplify.Auth.confirmSignIn( "123456", { result: AuthSignInResult? -> // result.nextStep.signInStep should be "DONE" now }, { error: AuthException -> Log.e("AuthQuickstart", error.toString()) })// Omit preferredFirstFactor. If the user has more than one factor available then// the next step will be CONTINUE_SIGN_IN_WITH_FIRST_FACTOR_SELECTION.val options: AuthSignInOptions = AWSCognitoAuthSignInOptions.builder() .authFlowType(AuthFlowType.USER_AUTH) .build()
// Step 1: Sign in the userval result = Amplify.Auth.signIn( username = "hello@example.com", password = null, options = options)
if (result.nextStep.signInStep == AuthSignInStep.CONTINUE_SIGN_IN_WITH_FIRST_FACTOR_SELECTION) { Log.i( "AuthQuickStart", "Available authentication factors for this user: ${result.nextStep.availableFactors}" )}
// Step 2: Select SMS OTP for sign inval selectFactorResult = Amplify.Auth.confirmSignIn(challengeResponse = AuthFactorType.SMS_OTP.challengeResponse)
if (result.nextStep.signInStep == AuthSignInStep.CONFIRM_SIGN_IN_WITH_OTP) { Log.i( "AuthQuickStart", "OTP code sent to ${result.nextStep.codeDeliveryDetails}" ) // Show UI to collect OTP}
// Step 3: Then pass that OTP into the confirmSignIn APIval confirmResult = Amplify.Auth.confirmSignIn(challengeResponse = "123456")
// confirmResult.nextStep.signInStep should be "DONE" now// Omit preferredFirstFactor. If the user has more than one factor available then// the next step will be CONTINUE_SIGN_IN_WITH_FIRST_FACTOR_SELECTION.AWSCognitoAuthSignInOptions options = AWSCognitoAuthSignInOptions.builder() .authFlowType(AuthFlowType.USER_AUTH) .build();
// Step 1: Sign in the userRxAmplify.Auth.signIn( username, null, // no password options).subscribe( result -> { if (result.getNextStep().getSignInStep() == AuthSignInStep.CONTINUE_SIGN_IN_WITH_FIRST_FACTOR_SELECTION) { Log.i( "AuthQuickstart", "Available authentication factors for this user: " + result.getNextStep().getAvailableFactors() ); } }, error -> Log.e("AuthQuickstart", error.toString()))
// Step 2: Select SMS OTP for sign inRxAmplify.Auth.confirmSignIn(AuthFactorType.SMS_OTP.getChallengeResponse()) .subscribe( result -> { if (result.getNextStep().getSignInStep() == AuthSignInStep.CONFIRM_SIGN_IN_WITH_OTP) { Log.i( "AuthQuickStart", "OTP code sent to " + result.getNextStep().getCodeDeliveryDetails() ) // Show UI to collect OTP } }, error -> Log.e("AuthQuickstart", error.toString()) );
// Step 3: Then pass that OTP into the confirmSignIn APIRxAmplify.Auth.confirmSignIn("123456") .subscribe( result -> { // result.getNextStep().getSignInStep() should be "DONE" now }, error -> Log.e("AuthQuickstart", error.toString()) );