Web uygulamanıza çok faktörlü kimlik doğrulama ekleyin

Identity Platform ile Firebase Authentication'a yükseltme yaptıysanız web uygulamanıza SMS çok faktörlü kimlik doğrulaması ekleyebilirsiniz.

Çok faktörlü kimlik doğrulama, uygulamanızın güvenliğini artırır. Saldırganlar genellikle şifreleri ve sosyal hesapları ele geçirirken, bir kısa mesajı ele geçirmek daha zordur.

Sen başlamadan önce

  1. Çok faktörlü kimlik doğrulamayı destekleyen en az bir sağlayıcıyı etkinleştirin. Telefonla kimlik doğrulama, anonim kimlik doğrulama ve Apple Game Center dışında her sağlayıcı MFA'yı destekler.

  2. Uygulamanızın kullanıcı e-postalarını doğruladığından emin olun. MFA, e-posta doğrulaması gerektirir. Bu, kötü niyetli aktörlerin, sahip olmadıkları bir e-postayla bir hizmete kaydolmalarını ve ardından ikinci bir faktör ekleyerek gerçek sahibi kilitlemelerini önler.

Çoklu kiracılığın kullanılması

Çok kiracılı bir ortamda kullanım için çok faktörlü kimlik doğrulamayı etkinleştiriyorsanız aşağıdaki adımları (bu belgedeki diğer talimatlara ek olarak) tamamladığınızdan emin olun:

  1. GCP Konsolunda çalışmak istediğiniz kiracıyı seçin.

  2. Kodunuzda, Auth örneğindeki tenantId alanını kiracınızın kimliğine ayarlayın. Örneğin:

    Web modüler API'si

    import { getAuth } from "firebase/auth";
    
    const auth = getAuth(app);
    auth.tenantId = "myTenantId1";
    

    Web ad alanlı API

    firebase.auth().tenantId = 'myTenantId1';
    

Çok faktörlü kimlik doğrulamayı etkinleştirme

  1. Firebase konsolunun Kimlik Doğrulama > Oturum açma yöntemi sayfasını açın.

  2. Gelişmiş bölümünde SMS Çok Faktörlü Kimlik Doğrulamayı etkinleştirin.

    Ayrıca uygulamanızı test edeceğiniz telefon numaralarını da girmelisiniz. İsteğe bağlı olmakla birlikte, geliştirme sırasında kısıtlamayı önlemek için test telefon numaralarının kaydedilmesi önemle tavsiye edilir.

  3. Uygulamanızın alan adını henüz yetkilendirmediyseniz Firebase konsolunun Kimlik Doğrulama > Ayarlar sayfasındaki izin verilenler listesine ekleyin.

Bir kayıt düzeni seçme

Uygulamanızın çok faktörlü kimlik doğrulama gerektirip gerektirmediğini ve kullanıcılarınızı nasıl ve ne zaman kaydedeceğinizi seçebilirsiniz. Bazı yaygın kalıplar şunları içerir:

  • Kullanıcının ikinci faktörünü kaydın bir parçası olarak kaydedin. Uygulamanız tüm kullanıcılar için çok faktörlü kimlik doğrulama gerektiriyorsa bu yöntemi kullanın.

  • Kayıt sırasında ikinci bir faktörün kaydedilmesi için atlanabilir bir seçenek sunun. Çok faktörlü kimlik doğrulamayı teşvik etmek isteyen ancak gerektirmeyen uygulamalar bu yaklaşımı tercih edebilir.

  • Kayıt ekranı yerine kullanıcının hesabından veya profil yönetimi sayfasından ikinci bir faktör ekleme olanağı sağlayın. Bu, kayıt işlemi sırasındaki anlaşmazlıkları en aza indirirken, aynı zamanda güvenlik konusunda hassas kullanıcılar için çok faktörlü kimlik doğrulamayı kullanılabilir hale getirir.

  • Kullanıcı artan güvenlik gereksinimlerine sahip özelliklere erişmek istediğinde ikinci bir faktörün aşamalı olarak eklenmesini zorunlu kılın.

reCAPTCHA doğrulayıcıyı ayarlama

SMS kodları göndermeden önce bir reCAPTCHA doğrulayıcı yapılandırmanız gerekir. Firebase, telefon numarası doğrulama isteklerinin uygulamanızın izin verilen etki alanlarından birinden gelmesini sağlayarak kötüye kullanımı önlemek için reCAPTCHA'yı kullanır.

reCAPTCHA istemcisini manuel olarak ayarlamanıza gerek yoktur; istemci SDK'sının RecaptchaVerifier nesnesi, gerekli tüm istemci anahtarlarını ve sırlarını otomatik olarak oluşturur ve başlatır.

Görünmez reCAPTCHA'yı kullanma

RecaptchaVerifier nesnesi, genellikle herhangi bir etkileşim gerektirmeden kullanıcıyı doğrulayabilen görünmez reCAPTCHA'yı destekler. Görünmez bir reCAPTCHA kullanmak için, size parametresi invisible olarak ayarlanmış bir RecaptchaVerifier oluşturun ve çok faktörlü kaydı başlatan kullanıcı arayüzü öğesinin kimliğini belirtin:

Web modüler API'si

import { RecaptchaVerifier } from "firebase/auth";

const recaptchaVerifier = new RecaptchaVerifier("sign-in-button", {
    "size": "invisible",
    "callback": function(response) {
        // reCAPTCHA solved, you can proceed with
        // phoneAuthProvider.verifyPhoneNumber(...).
        onSolvedRecaptcha();
    }
}, auth);

Web ad alanlı API

var recaptchaVerifier = new firebase.auth.RecaptchaVerifier('sign-in-button', {
'size': 'invisible',
'callback': function(response) {
  // reCAPTCHA solved, you can proceed with phoneAuthProvider.verifyPhoneNumber(...).
  onSolvedRecaptcha();
}
});

reCAPTCHA widget'ını kullanma

Görünür bir reCAPTCHA widget'ı kullanmak için, widget'ı içerecek bir HTML öğesi oluşturun, ardından kullanıcı arayüzü kapsayıcısının kimliğine sahip bir RecaptchaVerifier nesnesi oluşturun. Ayrıca isteğe bağlı olarak reCAPTCHA çözüldüğünde veya süresi dolduğunda çağrılacak geri aramaları da ayarlayabilirsiniz:

Web modüler API'si

import { RecaptchaVerifier } from "firebase/auth";

const recaptchaVerifier = new RecaptchaVerifier(
    "recaptcha-container",

    // Optional reCAPTCHA parameters.
    {
      "size": "normal",
      "callback": function(response) {
        // reCAPTCHA solved, you can proceed with
        // phoneAuthProvider.verifyPhoneNumber(...).
        onSolvedRecaptcha();
      },
      "expired-callback": function() {
        // Response expired. Ask user to solve reCAPTCHA again.
        // ...
      }
    }, auth
);

Web ad alanlı API

var recaptchaVerifier = new firebase.auth.RecaptchaVerifier(
  'recaptcha-container',
  // Optional reCAPTCHA parameters.
  {
    'size': 'normal',
    'callback': function(response) {
      // reCAPTCHA solved, you can proceed with phoneAuthProvider.verifyPhoneNumber(...).
      // ...
      onSolvedRecaptcha();
    },
    'expired-callback': function() {
      // Response expired. Ask user to solve reCAPTCHA again.
      // ...
    }
  });

reCAPTCHA'yı önceden oluşturma

İsteğe bağlı olarak, iki faktörlü kayda başlamadan önce reCAPTCHA'yı önceden oluşturabilirsiniz:

Web modüler API'si

recaptchaVerifier.render()
    .then(function (widgetId) {
        window.recaptchaWidgetId = widgetId;
    });

Web ad alanlı API

recaptchaVerifier.render()
  .then(function(widgetId) {
    window.recaptchaWidgetId = widgetId;
  });

render() çözümlendikten sonra, reCAPTCHA API'sine çağrı yapmak için kullanabileceğiniz reCAPTCHA widget kimliğini alırsınız:

var recaptchaResponse = grecaptcha.getResponse(window.recaptchaWidgetId);

RecaptchaVerifier, bu mantığı doğrulama yöntemiyle ortadan kaldırır, dolayısıyla grecaptcha değişkenini doğrudan kullanmanıza gerek yoktur.

İkinci bir faktörün kaydedilmesi

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

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

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

  3. Önceki bölümde gösterildiği gibi reCAPTCHA doğrulayıcıyı başlatın. RecaptchaVerifier örneği zaten yapılandırılmışsa bu adımı atlayın:

    Web modüler API'si

    import { RecaptchaVerifier } from "firebase/auth";
    
    const recaptchaVerifier = new RecaptchaVerifier('recaptcha-container-id', undefined, auth);
    

    Web ad alanlı API

    var recaptchaVerifier = new firebase.auth.RecaptchaVerifier('recaptcha-container-id');
    
  4. Kullanıcı için çok faktörlü bir oturum edinin:

    Web modüler API'si

    import { multiFactor } from "firebase/auth";
    
    multiFactor(user).getSession().then(function (multiFactorSession) {
        // ...
    });
    

    Web ad alanlı API

    user.multiFactor.getSession().then(function(multiFactorSession) {
      // ...
    })
    
  5. Kullanıcının telefon numarası ve çok faktörlü oturumla bir PhoneInfoOptions nesnesini başlatın:

    Web modüler API'si

    // Specify the phone number and pass the MFA session.
    const phoneInfoOptions = {
      phoneNumber: phoneNumber,
      session: multiFactorSession
    };
    

    Web ad alanlı API

    // Specify the phone number and pass the MFA session.
    var phoneInfoOptions = {
      phoneNumber: phoneNumber,
      session: multiFactorSession
    };
    
  6. Kullanıcının telefonuna bir doğrulama mesajı gönderin:

    Web modüler API'si

    import { PhoneAuthProvider } from "firebase/auth";
    
    const phoneAuthProvider = new PhoneAuthProvider(auth);
    phoneAuthProvider.verifyPhoneNumber(phoneInfoOptions, recaptchaVerifier)
        .then(function (verificationId) {
            // verificationId will be needed to complete enrollment.
        });
    

    Web ad alanlı API

    var phoneAuthProvider = new firebase.auth.PhoneAuthProvider();
    // Send SMS verification code.
    return phoneAuthProvider.verifyPhoneNumber(phoneInfoOptions, recaptchaVerifier)
      .then(function(verificationId) {
        // verificationId will be needed for enrollment completion.
      })
    

    Zorunlu olmasa da, kullanıcıları SMS mesajı alacakları ve standart ücretlerin geçerli olduğu konusunda önceden bilgilendirmek en iyi uygulamadır.

  7. İstek başarısız olursa reCAPTCHA'yı sıfırlayın ve ardından kullanıcının tekrar deneyebilmesi için önceki adımı tekrarlayın. reCAPTCHA belirteçleri yalnızca tek seferlik kullanım olduğundan, verifyPhoneNumber() işlevinin bir hata verdiğinde reCAPTCHA'yı otomatik olarak sıfırlayacağını unutmayın.

    Web modüler API'si

    recaptchaVerifier.clear();
    

    Web ad alanlı API

    recaptchaVerifier.clear();
    
  8. SMS kodu gönderildikten sonra kullanıcıdan kodu doğrulamasını isteyin:

    Web modüler API'si

    // Ask user for the verification code. Then:
    const cred = PhoneAuthProvider.credential(verificationId, verificationCode);
    

    Web ad alanlı API

    // Ask user for the verification code. Then:
    var cred = firebase.auth.PhoneAuthProvider.credential(verificationId, verificationCode);
    
  9. PhoneAuthCredential ile bir MultiFactorAssertion nesnesini başlatın:

    Web modüler API'si

    import { PhoneMultiFactorGenerator } from "firebase/auth";
    
    const multiFactorAssertion = PhoneMultiFactorGenerator.assertion(cred);
    

    Web ad alanlı API

    var multiFactorAssertion = firebase.auth.PhoneMultiFactorGenerator.assertion(cred);
    
  10. Kayıt işlemini tamamlayın. İsteğe bağlı olarak ikinci faktör için bir görünen ad belirleyebilirsiniz. Kimlik doğrulama akışı sırasında telefon numarası maskelendiğinden (örneğin, +1******1234) bu, birden fazla ikinci faktöre sahip kullanıcılar için kullanışlıdır.

    Web modüler API'si

    // Complete enrollment. This will update the underlying tokens
    // and trigger ID token change listener.
    multiFactor(user).enroll(multiFactorAssertion, "My personal phone number");
    

    Web ad alanlı API

    // Complete enrollment. This will update the underlying tokens
    // and trigger ID token change listener.
    user.multiFactor.enroll(multiFactorAssertion, 'My personal phone number');
    

Aşağıdaki kod, ikinci bir faktörü kaydetmenin tam bir örneğini gösterir:

Web modüler API'si

import {
    multiFactor, PhoneAuthProvider, PhoneMultiFactorGenerator,
    RecaptchaVerifier
} from "firebase/auth";

const recaptchaVerifier = new RecaptchaVerifier('recaptcha-container-id', undefined, auth);
multiFactor(user).getSession()
    .then(function (multiFactorSession) {
        // Specify the phone number and pass the MFA session.
        const phoneInfoOptions = {
            phoneNumber: phoneNumber,
            session: multiFactorSession
        };

        const phoneAuthProvider = new PhoneAuthProvider(auth);

        // Send SMS verification code.
        return phoneAuthProvider.verifyPhoneNumber(phoneInfoOptions, recaptchaVerifier);
    }).then(function (verificationId) {
        // Ask user for the verification code. Then:
        const cred = PhoneAuthProvider.credential(verificationId, verificationCode);
        const multiFactorAssertion = PhoneMultiFactorGenerator.assertion(cred);

        // Complete enrollment.
        return multiFactor(user).enroll(multiFactorAssertion, mfaDisplayName);
    });

Web ad alanlı API

var recaptchaVerifier = new firebase.auth.RecaptchaVerifier('recaptcha-container-id');
user.multiFactor.getSession().then(function(multiFactorSession) {
  // Specify the phone number and pass the MFA session.
  var phoneInfoOptions = {
    phoneNumber: phoneNumber,
    session: multiFactorSession
  };
  var phoneAuthProvider = new firebase.auth.PhoneAuthProvider();
  // Send SMS verification code.
  return phoneAuthProvider.verifyPhoneNumber(
      phoneInfoOptions, recaptchaVerifier);
})
.then(function(verificationId) {
  // Ask user for the verification code.
  var cred = firebase.auth.PhoneAuthProvider.credential(verificationId, verificationCode);
  var multiFactorAssertion = firebase.auth.PhoneMultiFactorGenerator.assertion(cred);
  // Complete enrollment.
  return user.multiFactor.enroll(multiFactorAssertion, mfaDisplayName);
});

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

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

Bir kullanıcıda iki faktörlü SMS doğrulamayla oturum açmak için:

  1. Kullanıcının ilk faktörüyle oturum açın, ardından auth/multi-factor-auth-required hatayı yakalayın. Bu hata bir çözümleyici, kayıtlı ikinci faktörlere ilişkin ipuçları ve kullanıcının birinci faktörle kimliğinin başarıyla doğrulandığını kanıtlayan temel bir oturum içerir.

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

    Web modüler API'si

    import { getAuth, getMultiFactorResolver} from "firebase/auth";
    
    const auth = getAuth();
    signInWithEmailAndPassword(auth, email, password)
        .then(function (userCredential) {
            // User successfully signed in and is not enrolled with a second factor.
        })
        .catch(function (error) {
            if (error.code == 'auth/multi-factor-auth-required') {
                // The user is a multi-factor user. Second factor challenge is required.
                resolver = getMultiFactorResolver(auth, error);
                // ...
            } else if (error.code == 'auth/wrong-password') {
                // Handle other errors such as wrong password.
            }
    });
    

    Web ad alanlı API

    firebase.auth().signInWithEmailAndPassword(email, password)
      .then(function(userCredential) {
        // User successfully signed in and is not enrolled with a second factor.
      })
      .catch(function(error) {
        if (error.code == 'auth/multi-factor-auth-required') {
          // The user is a multi-factor user. Second factor challenge is required.
          resolver = error.resolver;
          // ...
        } else if (error.code == 'auth/wrong-password') {
          // Handle other errors such as wrong password.
        } ...
      });
    

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

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

    Web modüler API'si

    // Ask user which second factor to use.
    // You can get the masked phone number via resolver.hints[selectedIndex].phoneNumber
    // You can get the display name via resolver.hints[selectedIndex].displayName
    
    if (resolver.hints[selectedIndex].factorId ===
        PhoneMultiFactorGenerator.FACTOR_ID) {
        // User selected a phone second factor.
        // ...
    } else if (resolver.hints[selectedIndex].factorId ===
               TotpMultiFactorGenerator.FACTOR_ID) {
        // User selected a TOTP second factor.
        // ...
    } else {
        // Unsupported second factor.
    }
    

    Web ad alanlı API

    // Ask user which second factor to use.
    // You can get the masked phone number via resolver.hints[selectedIndex].phoneNumber
    // You can get the display name via resolver.hints[selectedIndex].displayName
    if (resolver.hints[selectedIndex].factorId === firebase.auth.PhoneMultiFactorGenerator.FACTOR_ID) {
      // User selected a phone second factor.
      // ...
    } else if (resolver.hints[selectedIndex].factorId === firebase.auth.TotpMultiFactorGenerator.FACTOR_ID) {
      // User selected a TOTP second factor.
      // ...
    } else {
      // Unsupported second factor.
    }
    
  3. Önceki bölümde gösterildiği gibi reCAPTCHA doğrulayıcıyı başlatın. RecaptchaVerifier örneği zaten yapılandırılmışsa bu adımı atlayın:

    Web modüler API'si

    import { RecaptchaVerifier } from "firebase/auth";
    
    recaptchaVerifier = new RecaptchaVerifier('recaptcha-container-id', undefined, auth);
    

    Web ad alanlı API

    var recaptchaVerifier = new firebase.auth.RecaptchaVerifier('recaptcha-container-id');
    
  4. Kullanıcının telefon numarası ve çok faktörlü oturumla bir PhoneInfoOptions nesnesini başlatın. Bu değerler auth/multi-factor-auth-required hatasına iletilen resolver nesnesinde bulunur:

    Web modüler API'si

    const phoneInfoOptions = {
        multiFactorHint: resolver.hints[selectedIndex],
        session: resolver.session
    };
    

    Web ad alanlı API

    var phoneInfoOptions = {
      multiFactorHint: resolver.hints[selectedIndex],
      session: resolver.session
    };
    
  5. Kullanıcının telefonuna bir doğrulama mesajı gönderin:

    Web modüler API'si

    // Send SMS verification code.
    const phoneAuthProvider = new PhoneAuthProvider(auth);
    phoneAuthProvider.verifyPhoneNumber(phoneInfoOptions, recaptchaVerifier)
        .then(function (verificationId) {
            // verificationId will be needed for sign-in completion.
        });
    

    Web ad alanlı API

    var phoneAuthProvider = new firebase.auth.PhoneAuthProvider();
    // Send SMS verification code.
    return phoneAuthProvider.verifyPhoneNumber(phoneInfoOptions, recaptchaVerifier)
      .then(function(verificationId) {
        // verificationId will be needed for sign-in completion.
      })
    
  6. İstek başarısız olursa reCAPTCHA'yı sıfırlayın ve ardından kullanıcının tekrar deneyebilmesi için önceki adımı tekrarlayın:

    Web modüler API'si

    recaptchaVerifier.clear();
    

    Web ad alanlı API

    recaptchaVerifier.clear();
    
  7. SMS kodu gönderildikten sonra kullanıcıdan kodu doğrulamasını isteyin:

    Web modüler API'si

    const cred = PhoneAuthProvider.credential(verificationId, verificationCode);
    

    Web ad alanlı API

    // Ask user for the verification code. Then:
    var cred = firebase.auth.PhoneAuthProvider.credential(verificationId, verificationCode);
    
  8. PhoneAuthCredential ile bir MultiFactorAssertion nesnesini başlatın:

    Web modüler API'si

    const multiFactorAssertion = PhoneMultiFactorGenerator.assertion(cred);
    

    Web ad alanlı API

    var multiFactorAssertion = firebase.auth.PhoneMultiFactorGenerator.assertion(cred);
    
  9. İkincil kimlik doğrulamayı tamamlamak için resolver.resolveSignIn() öğesini çağırın. Daha sonra standart sağlayıcıya özel verileri ve kimlik doğrulama bilgilerini içeren orijinal oturum açma sonucuna erişebilirsiniz:

    Web modüler API'si

    // Complete sign-in. This will also trigger the Auth state listeners.
    resolver.resolveSignIn(multiFactorAssertion)
        .then(function (userCredential) {
            // userCredential will also contain the user, additionalUserInfo, 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,
            // userCredential.additionalUserInfo will contain data related to Google
            // provider that the user signed in with.
            // - user.credential contains the Google OAuth credential.
            // - user.credential.accessToken contains the Google OAuth access token.
            // - user.credential.idToken contains the Google OAuth ID token.
        });
    

    Web ad alanlı API

    // Complete sign-in. This will also trigger the Auth state listeners.
    resolver.resolveSignIn(multiFactorAssertion)
      .then(function(userCredential) {
        // userCredential will also contain the user, additionalUserInfo, 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,
        // userCredential.additionalUserInfo will contain data related to Google provider that
        // the user signed in with.
        // user.credential contains the Google OAuth credential.
        // user.credential.accessToken contains the Google OAuth access token.
        // user.credential.idToken contains the Google OAuth ID token.
      });
    

Aşağıdaki kod, çok faktörlü bir kullanıcıda oturum açmanın tam bir örneğini gösterir:

Web modüler API'si

import {
    getAuth,
    getMultiFactorResolver,
    PhoneAuthProvider,
    PhoneMultiFactorGenerator,
    RecaptchaVerifier,
    signInWithEmailAndPassword
} from "firebase/auth";

const recaptchaVerifier = new RecaptchaVerifier('recaptcha-container-id', undefined, auth);

const auth = getAuth();
signInWithEmailAndPassword(auth, email, password)
    .then(function (userCredential) {
        // User is not enrolled with a second factor and is successfully
        // signed in.
        // ...
    })
    .catch(function (error) {
        if (error.code == 'auth/multi-factor-auth-required') {
            const resolver = getMultiFactorResolver(auth, error);
            // Ask user which second factor to use.
            if (resolver.hints[selectedIndex].factorId ===
                PhoneMultiFactorGenerator.FACTOR_ID) {
                const phoneInfoOptions = {
                    multiFactorHint: resolver.hints[selectedIndex],
                    session: resolver.session
                };
                const phoneAuthProvider = new PhoneAuthProvider(auth);
                // Send SMS verification code
                return phoneAuthProvider.verifyPhoneNumber(phoneInfoOptions, recaptchaVerifier)
                    .then(function (verificationId) {
                        // Ask user for the SMS verification code. Then:
                        const cred = PhoneAuthProvider.credential(
                            verificationId, verificationCode);
                        const multiFactorAssertion =
                            PhoneMultiFactorGenerator.assertion(cred);
                        // Complete sign-in.
                        return resolver.resolveSignIn(multiFactorAssertion)
                    })
                    .then(function (userCredential) {
                        // User successfully signed in with the second factor phone number.
                    });
            } else if (resolver.hints[selectedIndex].factorId ===
                       TotpMultiFactorGenerator.FACTOR_ID) {
                // Handle TOTP MFA.
                // ...
            } else {
                // Unsupported second factor.
            }
        } else if (error.code == 'auth/wrong-password') {
            // Handle other errors such as wrong password.
        }
    });

Web ad alanlı API

var resolver;
firebase.auth().signInWithEmailAndPassword(email, password)
  .then(function(userCredential) {
    // User is not enrolled with a second factor and is successfully signed in.
    // ...
  })
  .catch(function(error) {
    if (error.code == 'auth/multi-factor-auth-required') {
      resolver = error.resolver;
      // Ask user which second factor to use.
      if (resolver.hints[selectedIndex].factorId ===
          firebase.auth.PhoneMultiFactorGenerator.FACTOR_ID) {
        var phoneInfoOptions = {
          multiFactorHint: resolver.hints[selectedIndex],
          session: resolver.session
        };
        var phoneAuthProvider = new firebase.auth.PhoneAuthProvider();
        // Send SMS verification code
        return phoneAuthProvider.verifyPhoneNumber(phoneInfoOptions, recaptchaVerifier)
          .then(function(verificationId) {
            // Ask user for the SMS verification code.
            var cred = firebase.auth.PhoneAuthProvider.credential(
                verificationId, verificationCode);
            var multiFactorAssertion =
                firebase.auth.PhoneMultiFactorGenerator.assertion(cred);
            // Complete sign-in.
            return resolver.resolveSignIn(multiFactorAssertion)
          })
          .then(function(userCredential) {
            // User successfully signed in with the second factor phone number.
          });
      } else if (resolver.hints[selectedIndex].factorId ===
        firebase.auth.TotpMultiFactorGenerator.FACTOR_ID) {
        // Handle TOTP MFA.
        // ...
      } else {
        // Unsupported second factor.
      }
    } else if (error.code == 'auth/wrong-password') {
      // Handle other errors such as wrong password.
    } ...
  });

Tebrikler! Çok faktörlü kimlik doğrulamayı kullanarak bir kullanıcıda başarıyla oturum açtınız.

Sıradaki ne