我可以使用Firebase的“电话号码身份验证"吗?电话号码验证功能? [英] Can I use Firebase "Phone Number Authentication" feature for the phone number verification purpose?

查看:135
本文介绍了我可以使用Firebase的“电话号码身份验证"吗?电话号码验证功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实际上是使用Firebase Google auth来登录用户,此后,我想将用户的基本详细信息带入数据库(其中还包括用户的手机号码),所以我的问题是可以使用电话号码身份验证只是为了验证用户的移动电话号码(使用OTP),然后可以将其存储到数据库中? 谢谢!

I am actually using Firebase Google auth for signing in the user and after that, I want to take the basic details of the user into the database which also includes the mobile number of a user, so my question is can use Phone Number Authentication just to verify the mobile number of user (using OTP) and after that I can store it into database? Thank You!

推荐答案

如果您只想使用Firebase电话身份验证进行电话号码验证,根据我的看法,您可以这样做,但是要实现以下目的:

If you want to use firebase phone authentication for phone number verification only, according to me you do this but by implementing following:

首先进入登录方法"页面,启用电话号码"登录方法,并使用此功能在电话号码上发送验证码

First in Sign-in Method page, enable the Phone Number sign-in method and to send verification code on phone number use this

PhoneAuthProvider.getInstance().verifyPhoneNumber(
    phoneNumber,        // Phone number to verify
    60,                 // Timeout duration
    TimeUnit.SECONDS,   // Unit of timeout
    this,               // Activity (for callback binding)
    mCallbacks);        // OnVerificationStateChangedCallbacks

您将在mCallbacks中获得响应,并使用此方法初始化回调

you will get response in mCallbacks and to initialize callback use this

mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {

@Override
public void onVerificationCompleted(PhoneAuthCredential credential) {
    // this method executed if phone number verified you can do your stuff here if you only want to verify phone number.
    // or you can also use this credentials for authenticate purpose.
}

@Override
public void onVerificationFailed(FirebaseException e) {
    // This callback is invoked in an invalid request for verification is made,
    // for instance if the the phone number format is not valid.

}

@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
    //and then execute your method if number entered is correct.
}
};

别忘了使用最新的Firebase依赖项,例如

Don't forgot to use latest firebase dependencies like

compile 'com.google.firebase:firebase-auth:11.4.2'

希望这会对您有所帮助.

Hope this will help you.

这篇关于我可以使用Firebase的“电话号码身份验证"吗?电话号码验证功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆