Android uygulamanıza çok öğeli kimlik doğrulaması ekleme

Firebase Authentication with Identity Platform sürümüne yükselttiyseniz Android uygulamanıza SMS ile çok faktörlü kimlik doğrulama ekleyebilirsiniz.

Çok öğeli kimlik doğrulama, uygulamanızın güvenliğini artırır. Saldırganlar genellikle güvenliği ihlal edilmiş şifreleri ve sosyal medya hesaplarını ele geçirse de kısa mesajları ele geçirmek daha zordur.

Başlamadan önce

  1. Çok öğeli kimlik doğrulamasını destekleyen en az bir sağlayıcıyı etkinleştirin. Telefon kimlik doğrulaması, anonim kimlik doğrulaması ve Apple Game Center hariç tüm sağlayıcılar çok faktörlü kimlik doğrulamayı destekler.

  2. Uygulamanızın kullanıcı e-postalarını doğruladığından emin olun. Çok faktörlü kimlik doğrulama için e-posta doğrulaması gerekir. Bu sayede, kötü niyetli kişilerin sahip olmadıkları bir e-posta adresiyle hizmete kaydolmaları ve ardından ikinci faktör ekleyerek gerçek sahibini engellemeleri önlenir.

  3. Uygulamanızın SHA-1 karma değerini Firebase konsoluna kaydedin (değişiklikleriniz otomatik olarak Google Cloud Authentication platformuna aktarılır).

    1. Uygulamanızın SHA-1 karmasını almak için İstemcinizin kimliğini doğrulama bölümündeki adımları uygulayın.

    2. Firebase konsolunda Ayarlar > Genel sekmesine gidin.

    3. Uygulamalarınız bölümünde Android uygulamanızı seçin ve SHA sertifika parmak izleri alanına SHA-1 parmak izinizi ekleyin.

Çok öğeli kimlik doğrulamasını etkinleştirme

  1. Firebase konsolunda Güvenlik > Kimlik doğrulama'ya gidin.

  2. Sign-in method (Oturum açma yöntemi) sekmesindeki Advanced (Gelişmiş) bölümünde SMS Multi-factor Authentication'ı (SMS Çok Faktörlü Kimlik Doğrulama) etkinleştirin.

    Uygulamanızı test etmek için kullanacağınız telefon numaralarını da girmeniz gerekir. İsteğe bağlı olsa da geliştirme sırasında kısıtlamadan kaçınmak için test telefon numaralarını kaydetmeniz önemle tavsiye edilir.

  3. Henüz yapmadıysanız uygulamanızın alan adını yetkilendirin:

    1. Firebase konsolunda Security (Güvenlik) > Authentication (Kimlik Doğrulama) > Settings (Ayarlar) sekmesine gidin.

    2. Yetkili alanlar bölümünde Alan ekle'yi tıklayın ve alanınızı ekleyin.

  4. İsteğe bağlı: SMS mesajlarının gönderilmesine izin vermek veya reddetmek istediğiniz bölgelerle ilgili bir politika belirleyin. SMS bölge politikası belirlemek, uygulamalarınızı SMS kötüye kullanımına karşı korumaya yardımcı olabilir.

    1. Firebase konsolunda Security (Güvenlik) > Authentication (Kimlik Doğrulama) > Settings (Ayarlar) sekmesine gidin.

    2. SMS bölge politikası bölümünde SMS bölge politikanızı oluşturun.

Kayıt modeli seçme

Uygulamanızın çok öğeli kimlik doğrulaması gerektirip gerektirmediğini ve kullanıcılarınızı nasıl ve ne zaman kaydettireceğinizi seçebilirsiniz. Yaygın kalıplardan bazıları şunlardır:

  • Kayıt işleminin bir parçası olarak kullanıcının ikinci faktörünü kaydedin. Uygulamanız tüm kullanıcılar için çok öğeli kimlik doğrulaması gerektiriyorsa bu yöntemi kullanın.

  • Kayıt sırasında ikinci faktör eklemek için atlanabilir bir seçenek sunun. Çok öğeli kimlik doğrulamasını zorunlu kılmak yerine teşvik etmek isteyen uygulamalar bu yaklaşımı tercih edebilir.

  • Kullanıcının, kaydolma ekranı yerine hesap veya profil yönetimi sayfasından ikinci faktör eklemesine olanak tanıyın. Bu sayede, kayıt sürecindeki zorluklar en aza indirilirken güvenliğe önem veren kullanıcılar için çok öğeli kimlik doğrulama kullanılabilir hale getirilir.

  • Kullanıcı, daha yüksek güvenlik gereksinimleri olan özelliklere erişmek istediğinde kademeli olarak ikinci bir faktör eklenmesini zorunlu kılma.

İkinci faktör kaydetme

Bir kullanıcı için yeni bir ikincil faktör kaydetmek istiyorsanız:

  1. Kullanıcının kimliğini yeniden doğrulayın.

  2. Kullanıcıdan telefon numarasını girmesini isteyin.

  3. Kullanıcı için çok faktörlü oturum oluşturun:

    Kotlin

    user.multiFactor.session.addOnCompleteListener { task ->
        if (task.isSuccessful) {
            val multiFactorSession: MultiFactorSession? = task.result
        }
    }
    

    Java

    user.getMultiFactor().getSession()
      .addOnCompleteListener(
          new OnCompleteListener<MultiFactorSession>() {
          @Override
          public void onComplete(@NonNull Task<MultiFactorSession> task) {
            if (task.isSuccessful()) {
              MultiFactorSession multiFactorSession = task.getResult();
            }
          }
          });
    
  4. Doğrulama sürecindeki farklı etkinlikleri işlemek için bir OnVerificationStateChangedCallbacks nesnesi oluşturun:

    Kotlin

    val callbacks = object : OnVerificationStateChangedCallbacks() {
        override fun onVerificationCompleted(credential: PhoneAuthCredential) {
            // This callback will be invoked in two situations:
            // 1) Instant verification. In some cases, the phone number can be
            //    instantly verified without needing to send or enter a verification
            //    code. You can disable this feature by calling
            //    PhoneAuthOptions.builder#requireSmsValidation(true) when building
            //    the options to pass to PhoneAuthProvider#verifyPhoneNumber().
            // 2) Auto-retrieval. On some devices, Google Play services can
            //    automatically detect the incoming verification SMS and perform
            //    verification without user action.
            this@MainActivity.credential = credential
        }
    
        override fun onVerificationFailed(e: FirebaseException) {
            // This callback is invoked in response to invalid requests for
            // verification, like an incorrect phone number.
            if (e is FirebaseAuthInvalidCredentialsException) {
                // Invalid request
                // ...
            } else if (e is FirebaseTooManyRequestsException) {
                // The SMS quota for the project has been exceeded
                // ...
            }
            // Show a message and update the UI
            // ...
        }
    
        override fun onCodeSent(
            verificationId: String, forceResendingToken: ForceResendingToken
        ) {
            // The SMS verification code has been sent to the provided phone number.
            // We now need to ask the user to enter the code and then construct a
            // credential by combining the code with a verification ID.
            // Save the verification ID and resending token for later use.
            this@MainActivity.verificationId = verificationId
            this@MainActivity.forceResendingToken = forceResendingToken
            // ...
        }
    }
    

    Java

    OnVerificationStateChangedCallbacks callbacks =
    new OnVerificationStateChangedCallbacks() {
      @Override
      public void onVerificationCompleted(PhoneAuthCredential credential) {
        // This callback will be invoked in two situations:
        // 1) Instant verification. In some cases, the phone number can be
        //    instantly verified without needing to send or enter a verification
        //    code. You can disable this feature by calling
        //    PhoneAuthOptions.builder#requireSmsValidation(true) when building
        //    the options to pass to PhoneAuthProvider#verifyPhoneNumber().
        // 2) Auto-retrieval. On some devices, Google Play services can
        //    automatically detect the incoming verification SMS and perform
        //    verification without user action.
        this.credential = credential;
      }
      @Override
      public void onVerificationFailed(FirebaseException e) {
        // This callback is invoked in response to invalid requests for
        // verification, like an incorrect phone number.
        if (e instanceof FirebaseAuthInvalidCredentialsException) {
        // Invalid request
        // ...
        } else if (e instanceof FirebaseTooManyRequestsException) {
        // The SMS quota for the project has been exceeded
        // ...
        }
        // Show a message and update the UI
        // ...
      }
      @Override
      public void onCodeSent(
        String verificationId, PhoneAuthProvider.ForceResendingToken token) {
        // The SMS verification code has been sent to the provided phone number.
        // We now need to ask the user to enter the code and then construct a
        // credential by combining the code with a verification ID.
        // Save the verification ID and resending token for later use.
        this.verificationId = verificationId;
        this.forceResendingToken = token;
        // ...
      }
    };
    
  5. Kullanıcının telefon numarası, çok faktörlü oturum ve geri çağırmalarınızla bir PhoneInfoOptions nesnesi başlatın:

    Kotlin

    val phoneAuthOptions = PhoneAuthOptions.newBuilder()
        .setPhoneNumber(phoneNumber)
        .setTimeout(30L, TimeUnit.SECONDS)
        .setMultiFactorSession(MultiFactorSession)
        .setCallbacks(callbacks)
        .build()
    

    Java

    PhoneAuthOptions phoneAuthOptions =
      PhoneAuthOptions.newBuilder()
          .setPhoneNumber(phoneNumber)
          .setTimeout(30L, TimeUnit.SECONDS)
          .setMultiFactorSession(multiFactorSession)
          .setCallbacks(callbacks)
          .build();
    

    Anında doğrulama varsayılan olarak etkindir. Devre dışı bırakmak için requireSmsValidation(true) yöntemini çağırın.

  6. Kullanıcının telefonuna doğrulama mesajı gönderme:

    Kotlin

    PhoneAuthProvider.verifyPhoneNumber(phoneAuthOptions)
    

    Java

    PhoneAuthProvider.verifyPhoneNumber(phoneAuthOptions);
    

    Zorunlu olmasa da kullanıcılara önceden SMS mesajı alacaklarını ve standart ücretlerin geçerli olduğunu bildirmek en iyi uygulamadır.

  7. SMS kodu gönderildikten sonra kullanıcıdan kodu doğrulamasını isteyin:

    Kotlin

    // Ask user for the verification code.
    val credential = PhoneAuthProvider.getCredential(verificationId, verificationCode)
    

    Java

    // Ask user for the verification code.
    PhoneAuthCredential credential
      = PhoneAuthProvider.getCredential(verificationId, verificationCode);
    
  8. PhoneAuthCredential ile bir MultiFactorAssertion nesnesi başlatın:

    Kotlin

    val multiFactorAssertion
      = PhoneMultiFactorGenerator.getAssertion(credential)
    

    Java

    MultiFactorAssertion multiFactorAssertion
      = PhoneMultiFactorGenerator.getAssertion(credential);
    
  9. Kayıt işlemini tamamlayın. İsteğe bağlı olarak, ikinci faktör için bir görünen ad belirtebilirsiniz. Telefon numarası, kimlik doğrulama akışı sırasında maskelendiğinden (ör. +1******1234) bu özellik, birden fazla ikinci faktörü olan kullanıcılar için kullanışlıdır.

    Kotlin

    // Complete enrollment. This will update the underlying tokens
    // and trigger ID token change listener.
    FirebaseAuth.getInstance()
        .currentUser
        ?.multiFactor
        ?.enroll(multiFactorAssertion, "My personal phone number")
        ?.addOnCompleteListener {
            // ...
        }
    

    Java

    // Complete enrollment. This will update the underlying tokens
    // and trigger ID token change listener.
    FirebaseAuth.getInstance()
      .getCurrentUser()
      .getMultiFactor()
      .enroll(multiFactorAssertion, "My personal phone number")
      .addOnCompleteListener(
          new OnCompleteListener<Void>() {
          @Override
          public void onComplete(@NonNull Task<Void> task) {
            // ...
          }
          });
    

Aşağıdaki kodda, ikinci faktör kaydetme işleminin eksiksiz bir örneği gösterilmektedir:

Kotlin

val multiFactorAssertion = PhoneMultiFactorGenerator.getAssertion(credential)
user.multiFactor.session
    .addOnCompleteListener { task ->
        if (task.isSuccessful) {
            val multiFactorSession = task.result
            val phoneAuthOptions = PhoneAuthOptions.newBuilder()
                .setPhoneNumber(phoneNumber)
                .setTimeout(30L, TimeUnit.SECONDS)
                .setMultiFactorSession(multiFactorSession)
                .setCallbacks(callbacks)
                .build()
            // Send SMS verification code.
            PhoneAuthProvider.verifyPhoneNumber(phoneAuthOptions)
        }
    }

// Ask user for the verification code.
val credential = PhoneAuthProvider.getCredential(verificationId, verificationCode)

val multiFactorAssertion = PhoneMultiFactorGenerator.getAssertion(credential)

// Complete enrollment.
FirebaseAuth.getInstance()
    .currentUser
    ?.multiFactor
    ?.enroll(multiFactorAssertion, "My personal phone number")
    ?.addOnCompleteListener {
        // ...
    }

Java

MultiFactorAssertion multiFactorAssertion = PhoneMultiFactorGenerator.getAssertion(credential);
user.getMultiFactor().getSession()
  .addOnCompleteListener(
      new OnCompleteListener<MultiFactorSession>() {
      @Override
      public void onComplete(@NonNull Task<MultiFactorSession> task) {
        if (task.isSuccessful()) {
          MultiFactorSession multiFactorSession = task.getResult();
          PhoneAuthOptions phoneAuthOptions =
            PhoneAuthOptions.newBuilder()
                .setPhoneNumber(phoneNumber)
                .setTimeout(30L, TimeUnit.SECONDS)
                .setMultiFactorSession(multiFactorSession)
                .setCallbacks(callbacks)
                .build();
          // Send SMS verification code.
          PhoneAuthProvider.verifyPhoneNumber(phoneAuthOptions);
        }
      }
      });

// Ask user for the verification code.
PhoneAuthCredential credential =
  PhoneAuthProvider.getCredential(verificationId, verificationCode);

MultiFactorAssertion multiFactorAssertion = PhoneMultiFactorGenerator.getAssertion(credential);
// Complete enrollment.
FirebaseAuth.getInstance()
  .getCurrentUser()
  .getMultiFactor()
  .enroll(multiFactorAssertion, "My personal phone number")
  .addOnCompleteListener(
      new OnCompleteListener<Void>() {
      @Override
      public void onComplete(@NonNull Task<Void> task) {
        // ...
      }
      });

Tebrikler! Bir kullanıcı için ikinci bir kimlik doğrulama faktörünü başarıyla kaydettiniz.

Kullanıcıların ikinci bir faktörle oturum açması

Bir kullanıcının iki faktörlü SMS doğrulamasıyla oturum açmasını sağlamak için:

  1. Kullanıcının ilk faktörüyle oturum açmasını sağlayın, ardından FirebaseAuthMultiFactorException istisnasını yakalayın. Bu hata, kullanıcının kayıtlı ikinci faktörlerini almak için kullanabileceğiniz bir çözümleyici içerir. Ayrıca, kullanıcının ilk faktörle kimliğini başarıyla doğruladığını kanıtlayan temel bir oturum içerir.

    Örneğin, kullanıcının ilk faktörü bir e-posta ve şifreyse:

    Kotlin

    FirebaseAuth.getInstance()
        .signInWithEmailAndPassword(email, password)
        .addOnCompleteListener(
            OnCompleteListener { task ->
                if (task.isSuccessful) {
                    // User is not enrolled with a second factor and is successfully
                    // signed in.
                    // ...
                    return@OnCompleteListener
                }
                if (task.exception is FirebaseAuthMultiFactorException) {
                    // The user is a multi-factor user. Second factor challenge is
                    // required.
                    val multiFactorResolver =
                        (task.exception as FirebaseAuthMultiFactorException).resolver
                    // ...
                } else {
                    // Handle other errors, such as wrong password.
                }
            })
    

    Java

    FirebaseAuth.getInstance()
      .signInWithEmailAndPassword(email, password)
      .addOnCompleteListener(
          new OnCompleteListener<AuthResult>() {
          @Override
          public void onComplete(@NonNull Task<AuthResult> task) {
            if (task.isSuccessful()) {
              // User is not enrolled with a second factor and is successfully
              // signed in.
              // ...
              return;
            }
            if (task.getException() instanceof FirebaseAuthMultiFactorException) {
              // The user is a multi-factor user. Second factor challenge is
              // required.
              MultiFactorResolver multiFactorResolver = task.getException().getResolver();
              // ...
            } else {
              // Handle other errors such as wrong password.
            }
          }
          });
    

    Kullanıcının ilk faktörü OAuth gibi bir birleşik sağlayıcıysa startActivityForSignInWithProvider() çağrıldıktan sonra hatayı yakalayın.

  2. Kullanıcının kayıtlı birden fazla ikincil faktörü varsa hangisini kullanacağını sorun:

    Kotlin

    // Ask user which second factor to use.
    // You can get the list of enrolled second factors using
    //   multiFactorResolver.hints
    
    // Check the selected factor:
    if (multiFactorResolver.hints[selectedIndex].factorId
        === PhoneMultiFactorGenerator.FACTOR_ID
    ) {
        // User selected a phone second factor.
        val selectedHint =
            multiFactorResolver.hints[selectedIndex] as PhoneMultiFactorInfo
    } else if (multiFactorResolver.hints[selectedIndex].factorId
        === TotpMultiFactorGenerator.FACTOR_ID) {
        // User selected a TOTP second factor.
    } else {
        // Unsupported second factor.
    }
    

    Java

    // Ask user which second factor to use.
    // You can get the masked phone number using
    // resolver.getHints().get(selectedIndex).getPhoneNumber()
    // You can get the display name using
    // resolver.getHints().get(selectedIndex).getDisplayName()
    if ( resolver.getHints()
                   .get(selectedIndex)
                   .getFactorId()
                   .equals( PhoneMultiFactorGenerator.FACTOR_ID ) ) {
    // User selected a phone second factor.
    MultiFactorInfo selectedHint =
      multiFactorResolver.getHints().get(selectedIndex);
    } else if ( resolver
                  .getHints()
                  .get(selectedIndex)
                  .getFactorId()
                  .equals(TotpMultiFactorGenerator.FACTOR_ID ) ) {
      // User selected a TOTP second factor.
    } else {
    // Unsupported second factor.
    }
    
  3. İpucu ve çok faktörlü oturumla bir PhoneAuthOptions nesnesi başlatın. Bu değerler, FirebaseAuthMultiFactorException öğesine eklenen çözümleyicide yer alır.

    Kotlin

    val phoneAuthOptions = PhoneAuthOptions.newBuilder()
        .setMultiFactorHint(selectedHint)
        .setTimeout(30L, TimeUnit.SECONDS)
        .setMultiFactorSession(multiFactorResolver.session)
        .setCallbacks(callbacks) // Optionally disable instant verification.
        // .requireSmsValidation(true)
        .build()
    

    Java

    PhoneAuthOptions phoneAuthOptions =
      PhoneAuthOptions.newBuilder()
          .setMultiFactorHint(selectedHint)
          .setTimeout(30L, TimeUnit.SECONDS)
          .setMultiFactorSession(multiFactorResolver.getSession())
          .setCallbacks(callbacks)
          // Optionally disable instant verification.
          // .requireSmsValidation(true)
          .build();
    
  4. Kullanıcının telefonuna doğrulama mesajı gönderme:

    Kotlin

    // Send SMS verification code
    PhoneAuthProvider.verifyPhoneNumber(phoneAuthOptions)
    

    Java

    // Send SMS verification code
    PhoneAuthProvider.verifyPhoneNumber(phoneAuthOptions);
    
  5. SMS kodu gönderildikten sonra kullanıcıdan kodu doğrulamasını isteyin:

    Kotlin

    // Ask user for the verification code. Then, pass it to getCredential:
    val credential =
        PhoneAuthProvider.getCredential(verificationId, verificationCode)
    

    Java

    // Ask user for the verification code. Then, pass it to getCredential:
    PhoneAuthCredential credential
        = PhoneAuthProvider.getCredential(verificationId, verificationCode);
    
  6. PhoneAuthCredential ile bir MultiFactorAssertion nesnesi başlatın:

    Kotlin

    val multiFactorAssertion = PhoneMultiFactorGenerator.getAssertion(credential)
    

    Java

    MultiFactorAssertion multiFactorAssertion
        = PhoneMultiFactorGenerator.getAssertion(credential);
    
  7. İkincil kimlik doğrulama işlemini tamamlamak için resolver.resolveSignIn() numaralı telefonu arayın. Ardından, standart sağlayıcıya özel verileri ve kimlik doğrulama bilgilerini içeren orijinal oturum açma sonucuna erişebilirsiniz:

    Kotlin

    multiFactorResolver
        .resolveSignIn(multiFactorAssertion)
        .addOnCompleteListener { task ->
            if (task.isSuccessful) {
                val authResult = task.result
                // AuthResult will also contain the user, additionalUserInfo,
                // and an optional credential (null for email/password)
                // associated with the first factor sign-in.
    
                // For example, if the user signed in with Google as a first
                // factor, authResult.getAdditionalUserInfo() will contain data
                // related to Google provider that the user signed in with;
                // authResult.getCredential() will contain the Google OAuth
                //   credential;
                // authResult.getCredential().getAccessToken() will contain the
                //   Google OAuth access token;
                // authResult.getCredential().getIdToken() contains the Google
                //   OAuth ID token.
            }
        }
    

    Java

    multiFactorResolver
      .resolveSignIn(multiFactorAssertion)
      .addOnCompleteListener(
          new OnCompleteListener<AuthResult>() {
          @Override
          public void onComplete(@NonNull Task<AuthResult> task) {
            if (task.isSuccessful()) {
              AuthResult authResult = task.getResult();
              // AuthResult will also contain the user, additionalUserInfo,
              // and an optional credential (null for email/password)
              // associated with the first factor sign-in.
              // For example, if the user signed in with Google as a first
              // factor, authResult.getAdditionalUserInfo() will contain data
              // related to Google provider that the user signed in with.
              // authResult.getCredential() will contain the Google OAuth
              // credential.
              // authResult.getCredential().getAccessToken() will contain the
              // Google OAuth access token.
              // authResult.getCredential().getIdToken() contains the Google
              // OAuth ID token.
            }
          }
          });
    

Aşağıdaki kodda, çok faktörlü bir kullanıcının oturum açma işleminin eksiksiz bir örneği gösterilmektedir:

Kotlin

FirebaseAuth.getInstance()
    .signInWithEmailAndPassword(email, password)
    .addOnCompleteListener { task ->
        if (task.isSuccessful) {
            // User is not enrolled with a second factor and is successfully
            // signed in.
            // ...
            return@addOnCompleteListener
        }
        if (task.exception is FirebaseAuthMultiFactorException) {
            val multiFactorResolver =
                (task.exception as FirebaseAuthMultiFactorException).resolver

            // Ask user which second factor to use. Then, get
            // the selected hint:
            val selectedHint =
                multiFactorResolver.hints[selectedIndex] as PhoneMultiFactorInfo

            // Send the SMS verification code.
            PhoneAuthProvider.verifyPhoneNumber(
                PhoneAuthOptions.newBuilder()
                    .setActivity(this)
                    .setMultiFactorSession(multiFactorResolver.session)
                    .setMultiFactorHint(selectedHint)
                    .setCallbacks(generateCallbacks())
                    .setTimeout(30L, TimeUnit.SECONDS)
                    .build()
            )

            // Ask user for the SMS verification code, then use it to get
            // a PhoneAuthCredential:
            val credential =
                PhoneAuthProvider.getCredential(verificationId, verificationCode)

            // Initialize a MultiFactorAssertion object with the
            // PhoneAuthCredential.
            val multiFactorAssertion: MultiFactorAssertion =
                PhoneMultiFactorGenerator.getAssertion(credential)

            // Complete sign-in.
            multiFactorResolver
                .resolveSignIn(multiFactorAssertion)
                .addOnCompleteListener { task ->
                    if (task.isSuccessful) {
                        // User successfully signed in with the
                        // second factor phone number.
                    }
                    // ...
                }
        } else {
            // Handle other errors such as wrong password.
        }
    }

Java

FirebaseAuth.getInstance()
  .signInWithEmailAndPassword(email, password)
  .addOnCompleteListener(
      new OnCompleteListener<AuthResult>() {
      @Override
      public void onComplete(@NonNull Task<AuthResult> task) {
        if (task.isSuccessful()) {
          // User is not enrolled with a second factor and is successfully
          // signed in.
          // ...
          return;
        }
        if (task.getException() instanceof FirebaseAuthMultiFactorException) {
          FirebaseAuthMultiFactorException e =
            (FirebaseAuthMultiFactorException) task.getException();

          MultiFactorResolver multiFactorResolver = e.getResolver();

          // Ask user which second factor to use.
          MultiFactorInfo selectedHint =
            multiFactorResolver.getHints().get(selectedIndex);

          // Send the SMS verification code.
          PhoneAuthProvider.verifyPhoneNumber(
            PhoneAuthOptions.newBuilder()
                .setActivity(this)
                .setMultiFactorSession(multiFactorResolver.getSession())
                .setMultiFactorHint(selectedHint)
                .setCallbacks(generateCallbacks())
                .setTimeout(30L, TimeUnit.SECONDS)
                .build());

          // Ask user for the SMS verification code.
          PhoneAuthCredential credential =
            PhoneAuthProvider.getCredential(verificationId, verificationCode);

          // Initialize a MultiFactorAssertion object with the
          // PhoneAuthCredential.
          MultiFactorAssertion multiFactorAssertion =
            PhoneMultiFactorGenerator.getAssertion(credential);

          // Complete sign-in.
          multiFactorResolver
            .resolveSignIn(multiFactorAssertion)
            .addOnCompleteListener(
                new OnCompleteListener<AuthResult>() {
                  @Override
                  public void onComplete(@NonNull Task<AuthResult> task) {
                  if (task.isSuccessful()) {
                    // User successfully signed in with the
                    // second factor phone number.
                  }
                  // ...
                  }
                });
        } else {
          // Handle other errors such as wrong password.
        }
      }
      });

Tebrikler! Çok öğeli kimlik doğrulama kullanarak bir kullanıcının oturum açmasını sağladınız.

Sırada ne var?