使用Firebase Phone Auth验证电话号码是否需要完全登录?

时间:2017-09-19 14:54:00

标签: firebase-authentication firebaseui

有关通过电话号码进行身份验证的firebase身份验证的问题。

我想知道是否可以将“电话提供商”与Google Auth Provider联系起来。 docs中没有明确提及它。

让我摸不着头脑的是 - Link Multiple Auth Provider文档谈到开始通过新的提供商(电话提供商)验证您要链接到现有提供商(谷歌提供商),但随后停止致电FirebaseAuth.signInWithXXX

所以从理论上来说就像:

  1. 用户通过谷歌(谷歌idp提供商)
  2. 登录
  3. 用户启动手机身份验证(电话号码提供商) - 并收到短信。
  4. 在某些情况下,SMS应触发自动验证,或者他从短信中输入6位数代码
  5. 但根据有关帐户关联的文档,我们可以调用FirebaseAuth.signInWithXXX,而不是在此处致电FirebaseUser.linkWithCredential(PhoneAuthCredential)
  6. 所以我想知道如果没有明确登录PhoneAuthCredential,电话号码验证是否完整?

2 个答案:

答案 0 :(得分:4)

您可以将PhoneAuthCredential链接到现有用户(在您的情况下是具有GoogleAuthProvider的用户)。

使用Google登录用户后。 然后,您将浏览PhoneAuthProvider.getInstance().verifyPhoneNumber(phoneNumber, ...) 这将通过PhoneAuthCredential或验证ID解决。然后,您可以通过PhoneAuthProvider.getCredential请求SMS代码并实例化PhoneAuthCredential。

然后,您可以将该凭据链接到currentUser:currentUser.linkWithCredential(phoneAuthCredential)

答案 1 :(得分:0)

对于将来的用户和javascript用户,这是实现此目标的一种方法:

const phoneCreds = firebase.auth.PhoneAuthProvider.credential(this.windowRef.confirmationResult.verificationId, phoneConfirmCode);

        firebase.auth().currentUser.linkAndRetrieveDataWithCredential(phoneCreds)
            .then(response => {
                console.log('*********', response);
                // Manage other firestore data
            })
            .catch((error) => {
                console.log('error', error);
            });
相关问题