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

Identity Platform ile Firebase Authentication'a yükselttiyseniz web uygulamanıza SMS ile çok öğeli kimlik doğrulamasını ekleyebilirsiniz.

Çok öğeli kimlik doğrulaması, uygulamanızın güvenliğini artırır. Saldırganlar genellikle şifrelerin ve sosyal hesapların güvenliğini ihlal etse 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. Her sağlayıcı; telefon kimlik doğrulaması, anonim kimlik doğrulama ve Apple Game Center haricinde MFA'yı destekler.

  2. SMS kimlik doğrulamasını kullanmayı planladığınız bölgeleri etkinleştirin. Firebase, projelerinizi varsayılan olarak daha güvenli bir durumda oluşturmanıza yardımcı olan tamamen engelleyen bir SMS bölge politikası kullanır.

  3. Uygulamanızın kullanıcı e-postalarını doğruladığından emin olun. MFA için e-posta doğrulaması gerekir. Bu, kötü niyetli kişilerin sahip olmadıkları bir e-postayla bir hizmete kaydolup ikinci bir etmen ekleyerek gerçek sahibini kilitlemelerini önler.

Çok kiracılı yapıyı kullanma

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

  1. GCP Console'da, birlikte çalışmak istediğiniz kiracıyı seçin.

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

    Web modüler API

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

    Web ad alanı API'si

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

Çok öğeli kimlik doğrulamasını 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 Öğeli Kimlik Doğrulaması'nı etkinleştirin.

    Ayrıca uygulamanızı test edeceğiniz 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ın kaydedilmesi önemle tavsiye edilir.

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

Kayıt kalıbı seçme

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

  • Kullanıcının ikinci faktörünü kayıt işleminin bir parçası olarak 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 bir faktör kaydettirmek için atlanabilir bir seçenek sunun. Çok öğeli kimlik doğrulamasını teşvik etmek isteyen ancak gerektirmeyen uygulamalar bu yaklaşımı tercih edebilir.

  • Kayıt ekranı yerine, kullanıcının hesap veya profil yönetimi sayfasından ikinci bir faktör ekleme olanağı sunun. Bu sayede hem kayıt işlemi sırasında yaşanabilecek sorunları en aza indirir hem de güvenlik açısından hassas kullanıcılar için çok öğeli kimlik doğrulamasını kullanılabilir hâle getirirsiniz.

  • Kullanıcı daha yüksek güvenlik gereksinimleri olan ö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önderebilmeniz için önce bir reCAPTCHA doğrulayıcı yapılandırmanız gerekir. Firebase, telefon numarası doğrulama isteklerinin uygulamanızın izin verilen alanlarından birinden gelmesini sağlayarak kötüye kullanımı önlemek için reCAPTCHA'yı kullanır.

Manuel olarak reCAPTCHA istemcisi ayarlamanıza gerek yoktur. İstemci SDK'sının RecaptchaVerifier nesnesi, gerekli istemci anahtarlarını ve gizli anahtarları otomatik olarak oluşturup 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 öğeli kaydı başlatan kullanıcı arayüzü öğesinin kimliğini belirtin:

Web modüler API

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 alanı API'si

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ı kimliğine sahip bir RecaptchaVerifier nesnesi oluşturun. İsteğe bağlı olarak, reCAPTCHA çözüldüğünde veya süresi dolduğunda çağrılacak geri çağırmalar da ayarlayabilirsiniz:

Web modüler API

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 alanı API'si

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ü kayıt başlatmadan önce reCAPTCHA'yı önceden oluşturabilirsiniz:

Web modüler API

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

Web ad alanı API'si

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

render() sorunu çözüldükten sonra reCAPTCHA'nın widget kimliğini alırsınız. Bu widget'ı reCAPTCHA API'ye çağrı yapmak için kullanabilirsiniz:

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

RecaptchaVerifier, doğrulama yöntemiyle bu mantığı soyutladığından grecaptcha değişkenini doğrudan işlemeniz gerekmez.

İkinci faktör kaydettirme

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

  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

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

    Web ad alanı API'si

    var recaptchaVerifier = new firebase.auth.RecaptchaVerifier('recaptcha-container-id');
    
  4. Kullanıcı için çok öğeli oturum alma:

    Web modüler API

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

    Web ad alanı API'si

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

    Web modüler API

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

    Web ad alanı API'si

    // 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

    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 alanı API'si

    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 olmamakla birlikte, kullanıcılara bir SMS mesajı alacaklarını ve standart ücretlerin geçerli olacağını önceden bildirmek 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 jetonları yalnızca tek kullanımlık olduğundan verifyPhoneNumber(), hata verdiğinde reCAPTCHA'yı otomatik olarak sıfırlar.

    Web modüler API

    recaptchaVerifier.clear();
    

    Web ad alanı API'si

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

    Web modüler API

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

    Web ad alanı API'si

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

    Web modüler API

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

    Web ad alanı API'si

    var multiFactorAssertion = firebase.auth.PhoneMultiFactorGenerator.assertion(cred);
    
  10. Kaydı 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 bu yöntem, birden fazla ikinci faktöre sahip kullanıcılar için yararlıdır (örneğin, +1******1234).

    Web modüler API

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

    Web ad alanı API'si

    // 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 kodda, ikinci bir faktör kaydetmeyle ilgili tam bir örnek gösterilmektedir:

Web modüler API

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 alanı API'si

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 bir kimlik doğrulama faktörünü başarıyla kaydettiniz.

İkinci faktörle kullanıcıların oturum açmasını sağlama

İki faktörlü SMS doğrulamasıyla bir kullanıcının oturumunu açmak için:

  1. Kullanıcının ilk faktörle oturum açmasını sağlayın, ardından auth/multi-factor-auth-required hatasını yakalayın. Bu hata bir çözümleyici, kayıtlı ikinci faktörlerle ilgili ipuçları ve kullanıcının ilk faktörle 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 şifreyse:

    Web modüler API

    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 alanı API'si

    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 birleşik bir sağlayıcıysa signInWithPopup() veya signInWithRedirect() çağrısından sonra hatayı yakalayın.

  2. Birden fazla ikincil faktör kayıtlıysa hangisinin kullanılacağını sorun:

    Web modüler 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 ===
        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 alanı 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 === 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

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

    Web ad alanı API'si

    var recaptchaVerifier = new firebase.auth.RecaptchaVerifier('recaptcha-container-id');
    
  4. Kullanıcının telefon numarası ve çok öğeli 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

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

    Web ad alanı API'si

    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

    // 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 alanı API'si

    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

    recaptchaVerifier.clear();
    

    Web ad alanı API'si

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

    Web modüler API

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

    Web ad alanı API'si

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

    Web modüler API

    const multiFactorAssertion = PhoneMultiFactorGenerator.assertion(cred);
    

    Web ad alanı API'si

    var multiFactorAssertion = firebase.auth.PhoneMultiFactorGenerator.assertion(cred);
    
  9. İkincil kimlik doğrulamayı tamamlamak için resolver.resolveSignIn() numaralı telefonu arayın. Böylece, 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

    // 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 alanı 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.
      });
    

Aşağıdaki kodda, çok öğeli bir kullanıcının oturum açmasıyla ilgili tam bir örnek gösterilmektedir:

Web modüler API

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 alanı API'si

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 öğeli kimlik doğrulamayı kullanarak bir kullanıcının oturumunu başarıyla açtınız.

Sırada ne var?