Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resend SMS verification in Firebase Phone Authentication Android?

Tags:

According to Firebase documentation (https://firebase.google.com/docs/auth/android/phone-auth#send-a-verification-code-to-the-users-phone), there is callback for handling the phone number authentication.

mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {      @Override     public void onVerificationCompleted(PhoneAuthCredential credential) {          Log.d(TAG, "onVerificationCompleted:" + credential);         signInWithPhoneAuthCredential(credential);     }      @Override     public void onVerificationFailed(FirebaseException e) {          Log.w(TAG, "onVerificationFailed", e);     }      @Override     public void onCodeSent(String verificationId,                            PhoneAuthProvider.ForceResendingToken token) {          Log.d(TAG, "onCodeSent:" + verificationId);          // Save verification ID and resending token so we can use them later         mVerificationId = verificationId;         mResendToken = token;     } }; 

My question is on onCodeSent method. It said on the doc here (https://firebase.google.com/docs/reference/android/com/google/firebase/auth/PhoneAuthProvider.ForceResendingToken)

that the token can be used to force re-sending an SMS verification code. However, after doing some research on the doc I still don't know how.

I would like to ask how to use this token to resend the SMS verification ?

like image 350
Boonya Kitpitak Avatar asked Jun 22 '17 01:06

Boonya Kitpitak


People also ask

How do you resend OTP flutters?

Record the value of forceResendingToken as resendToken from codeSent callback while sending the otp for first time, then to resend the otp, add one extra parameter forceResendingToken: resendToken in auth. verifyPhoneNumber() function.

How do I remove Captcha verification from Firebase phone auth using Android?

Don't forget to go in Firebase Project Settings > App check > and Register firebase project in SafetyNet and Play Integrity register with default time token 1 hour and u will remove reCaptcha from phone auth OTP! That's awesome.

Can we send OTP using Firebase?

You can use Firebase Authentication to sign in a user by sending an SMS message to the user's phone. The user signs in using a one-time code contained in the SMS message.

Is Firebase SMS verification free?

Implementing phone number authentication involves sending an SMS to a user's mobile. To do so, we need to pay for SMS services. But via Firebase, we can send an SMS without any cost.


1 Answers

Source: Firebase Quickstarts for Android

This is the method used to resend SMS Verifications.

private void resendVerificationCode(String phoneNumber,                                     PhoneAuthProvider.ForceResendingToken token) {     PhoneAuthProvider.getInstance().verifyPhoneNumber(             phoneNumber,        // Phone number to verify             60,                 // Timeout duration             TimeUnit.SECONDS,   // Unit of timeout             this,               // Activity (for callback binding)             mCallbacks,         // OnVerificationStateChangedCallbacks             token);             // ForceResendingToken from callbacks } 
like image 132
GGWP Avatar answered Sep 29 '22 21:09

GGWP