无需登录即可使用Firebase Phone Auth进行移动OTP验证 [英] Mobile OTP Verification without signing in using Firebase Phone Auth
问题描述
我当前正在制作一个android应用,需要验证用户是否使用OTP输入了正确的手机号码.用户已经使用他的电子邮件和密码登录了该应用程序.现在,我需要验证用户输入的手机号码,而不使用firebase电话auth的signInWithCrendntial()方法.我该怎么办?
I am currently making an android app where I need to verify if the user is entering correct mobile number using the OTP. The user is already signed in the application using his email and password. Now I need to verify the mobile number the user enters without using the signInWithCrendntial() method of firebase phone auth. How do i go about it ?
我的mCallbacks是
My mCallbacks is
@Override
public void onVerificationCompleted(PhoneAuthCredential credential) {
Toast.makeText(getApplicationContext(), "Verification Complete", Toast.LENGTH_SHORT).show();
showMessage("Success!!","OTP verified!" + credential);
cred = credential;
//btn_add_guest.setEnabled(true);
}
@Override
public void onVerificationFailed(FirebaseException e) {
Toast.makeText(getApplicationContext(), "Verification Failed", Toast.LENGTH_SHORT).show();
Log.i(TAG,"Error is "+e.getMessage());
}
@Override
public void onCodeSent(String verificationId,
PhoneAuthProvider.ForceResendingToken token) {
Toast.makeText(getApplicationContext(), "Code Sent", Toast.LENGTH_SHORT).show();
mVerificationId = verificationId;
mResendToken = token;
Log.i(TAG,"VERFICATION ID IS"+mVerificationId);
Log.i(TAG,"RESEND TOKEN"+mResendToken);
btn_add_guest.setEnabled(false);
}
};
我要在按钮上调用此方法,在用户输入OTP的put_otp是textView的情况下按下.
I m calling this method on button Pressed where put_otp is textView where user enters the OTP.
verifyPhoneNumberWithCode(mVerificationId,put_otp.getText().toString());
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(mVerificationId, put_otp.getText().toString());
Log.i(TAG,credential.getProvider());
private void verifyPhoneNumberWithCode(String verificationId, String code) {
Log.i(TAG,"RESEND TOKEN IN METHOD IS"+mResendToken); if(code.equals(mResendToken)&&verificationId.equals(mVerificationId)){
Toast.makeText(AddGuestActivity.this, "Verification Success", Toast.LENGTH_SHORT).show();
btn_add_guest.setEnabled(true);
}
else
Toast.makeText(this,"Please provide correct OTP",Toast.LENGTH_SHORT).show();
}
推荐答案
You can link an email/pass account with a phone account https://firebase.google.com/docs/auth/android/account-linking?authuser=0
这篇关于无需登录即可使用Firebase Phone Auth进行移动OTP验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!