Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does SMS Retriever API is required in Firebase authentication for otp auto fill?

I am using Firebase auth api to verify user phone number. Currently in my case I have one screen where user put phone number and on second screen otp. As per documentation firebase automatic retrieve otp and start verification process most of time. So my question is it already implemented this SMS Retriever API in Firebase Auth SDK or Should I implement it myself to retrieve SMS and auto fill OTP.

like image 734
Rakesh Avatar asked Dec 17 '18 05:12

Rakesh


People also ask

What is SMS retriever API?

With the SMS Retriever API, you can perform SMS-based user verification in your Android app automatically, without requiring the user to manually type verification codes, and without requiring any extra app permissions.

Is firebase SMS verification free?

But via Firebase, we can send an SMS without any cost. Firebase offers 10,000 verifications per month under the free plan.


1 Answers

Nope. we don't need to manage SMS-retrival scenario.

If device contains same SIM-card, It's automatically managed by PhoneAuthProvider.OnVerificationStateChangedCallbacks in onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) method.

Snippet:

private PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {

        @Override
        public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
            Toast.makeText(FCMsmsTest.this, "onVerificationCompleted " + phoneAuthCredential.toString(), Toast.LENGTH_SHORT).show();
            signInWithPhoneAuthCredential(phoneAuthCredential);
        }

        @Override
        public void onVerificationFailed(FirebaseException e) {
            Toast.makeText(FCMsmsTest.this, "onVerificationFailed " + e.toString(), Toast.LENGTH_SHORT).show();

            if (e instanceof FirebaseAuthInvalidCredentialsException) {
                Toast.makeText(FCMsmsTest.this, "Invalid Request " + e.toString(), Toast.LENGTH_SHORT).show();
            } else if (e instanceof FirebaseTooManyRequestsException) {
                Toast.makeText(FCMsmsTest.this, "The SMS quota for the project has been exceeded " + e.toString(), Toast.LENGTH_SHORT).show();
            }
        }

        @Override
        public void onCodeSent(String verificationId,
                               PhoneAuthProvider.ForceResendingToken token) {
            Toast.makeText(FCMsmsTest.this, "onCodeSent " + verificationId, Toast.LENGTH_SHORT).show();
            editText.setText("");

            mVerificationId = verificationId;
            PhoneAuthProvider.ForceResendingToken mResendToken = token;

            showDialog();
        }
    };
like image 63
Rumit Patel Avatar answered Sep 29 '22 01:09

Rumit Patel