SMS verification code request failed with unknown status code 17006, while authenticating with firebase phone-auth api on android
Asked Answered
A

5

8

I don't know what does this error mean. I've search a lot on Google, but couldn't find why am I getting this error.

E/FirebaseAuth: [SmsRetrieverHelper] SMS verification code request failed: unknown status code: 17006 null

I'm trying to authenticate android client with firebase phone auth sign-in method, and trying to verify their phone number by sending a verification code on their phone. No code is being sent and no callback function is called. I don't know what is the problem here

Here's the activity for getting phone number from edittext, and sending the verification code on that phone number, and starting next activity, where user will enter the code they have got:

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.Log;
import android.widget.Button;
import android.widget.EditText;

import com.google.firebase.FirebaseException;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.PhoneAuthCredential;
import com.google.firebase.auth.PhoneAuthOptions;
import com.google.firebase.auth.PhoneAuthProvider;

import java.util.concurrent.TimeUnit;

public class PhoneOtpAuth extends AppCompatActivity {

    private FirebaseAuth mAuth;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_phone_otp_auth);

        EditText phoneNumberEditText = findViewById(R.id.phone_number);
        Button signIn = findViewById(R.id.sign_in_button);

        mAuth = FirebaseAuth.getInstance();

        signIn.setOnClickListener(v -> {
            String phoneNumber = phoneNumberEditText.getText().toString();

            PhoneAuthOptions options =
                    PhoneAuthOptions.newBuilder(mAuth)
                            .setPhoneNumber(phoneNumber)
                            .setTimeout(60L, TimeUnit.SECONDS)
                            .setActivity(PhoneOtpAuth.this)
                            .setCallbacks(callbacks)
                            .build();

            PhoneAuthProvider.verifyPhoneNumber(options);
        });
    }

    PhoneAuthProvider.OnVerificationStateChangedCallbacks callbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
        @Override
        public void onVerificationCompleted(@NonNull PhoneAuthCredential phoneAuthCredential) {
            Intent signUpIntent = new Intent(PhoneOtpAuth.this, DriverSignup.class);
            startActivity(signUpIntent);
            finish();
        }

        @Override
        public void onVerificationFailed(@NonNull FirebaseException e) {

        }

        @Override
        public void onCodeSent(@NonNull String s, @NonNull PhoneAuthProvider.ForceResendingToken forceResendingToken) {    
            Intent otpVerificationIntent = new Intent(PhoneOtpAuth.this, OtpVerificationActivity.class);
            otpVerificationIntent.putExtra("VerificationId", s);
            startActivity(otpVerificationIntent);
            finish();
        }
    };
}

Here's the activity for verifying the verification code the user has got from the last (above one) activity:

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.FirebaseException;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.PhoneAuthCredential;
import com.google.firebase.auth.PhoneAuthOptions;
import com.google.firebase.auth.PhoneAuthProvider;

import java.util.concurrent.TimeUnit;

public class OtpVerificationActivity extends AppCompatActivity {

    private String otp;

    private FirebaseAuth mAuth;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_otp_verification);

        EditText otpEditText = findViewById(R.id.otp);
        Button verifyOtp = findViewById(R.id.verify_otp_button);

        mAuth = FirebaseAuth.getInstance();

        otp = otpEditText.getText().toString();
        String verificationId = getIntent().getExtras().getString("VerificationId");
        FirebaseAuth mAuth = getIntent().getExtras().getParcelable("mAuth");

        verifyOtp.setOnClickListener(v -> {
            PhoneAuthCredential phoneAuthCredential = PhoneAuthProvider.getCredential(verificationId, otp);

            mAuth.signInWithCredential(phoneAuthCredential)
                    .addOnCompleteListener(task -> {
                        if(task.isSuccessful()) {
                            Intent signUpIntent = new Intent(OtpVerificationActivity.this, DriverSignup.class);
                            startActivity(signUpIntent);
                            finish();
                        }
                    });
        });
    }
}
Acropetal answered 2/2, 2021 at 18:1 Comment(0)
B
11

Well I think you might have forgotten to enable the Phone Sign-in method in your firebase console

Try adding phone as Sign-in providers and try again.

Bellyache answered 11/2, 2021 at 6:14 Comment(1)
I had the same problem and it was solved after enabling this optionJaenicke
E
10

When you repetitively use a specific phone number, signing in and out for the sake of testing, without adding it to "Phone Numbers for Testing", Google might eventually block it temporarily with an error indicating unusual behavior has been detected, or with error: "SMS verification code request failed: unknown status code: 17010 null".

Edit: Please for Accessing the "Phone Numbers for Testing" find the screenshot below:

enter image description here

Euhemerize answered 5/5, 2021 at 4:54 Comment(4)
[SmsRetrieverHelper] SMS verification code request failed: unknown status code: 17052 Exceeded per phone number quota for sending verification codes. what should i doDelcine
update your Firebase plan to spark @DelcineSpiral
where is "Phone Number for TestingWarfold
@SaiedRahimi Salam, please for Accessing "Phone Numbers for Testing" find the screenshot above.Euhemerize
B
4

Make sure the device is connected to the internet. Also In the Google Cloud Console, enable the Android DeviceCheck API for your project. That way firebase SDK can verify the device to proceed with authentication.

Bolometer answered 7/4, 2021 at 20:10 Comment(0)
M
1

I resolved mine by following these 2 simple steps:

  1. Selecting allow selected Regions under Authentication like shown in the picture: enter image description here

  2. By unliking my firebase app from Google Play under Project Settings/Integrations like below

enter image description here

Melia answered 10/11, 2023 at 12:2 Comment(0)
E
0

Add the number to the test numbers but pay attention That The format of the number should be valid for the used country key

Ex: if we are using US number it should be something like this +1-212-456-7890

if 212 is not a valid open for US numbers it won't work

Enact answered 15/7, 2024 at 12:24 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.