如何测试将Firebase列入白名单的电话号码

时间:2019-03-23 11:40:03

标签: java android firebase-authentication whitelist

根据documentation,我了解我无法将真实的电话号码添加到白名单中:

  

Firebase身份验证不允许您将真实用户使用的现有电话号码列入白名单。

我不想像普通用户那样注册我的真实设备,我想对其进行测试,但是我不知道如何将包含真实电话号码的设备添加到白名单中。

这是到目前为止我用于电话验证的代码(可以正常使用,但我不知道如何实现白名单部分):

    private void sendVerificationCode() {
    //THE USER PHONE NUMBER THAT HE ENTERED
    if (phoneNumberEditText.getText().toString().length() == 0) {
        Toast.makeText(this, "נא למלא את השדה", Toast.LENGTH_SHORT).show();
    } else {
        String mPhoneNumber = phoneNumberEditText.getText().toString();

        //checks the input of the edit text
        isEditTextLegit(mPhoneNumber.isEmpty(), "נא למלא מספר פלאפון", phoneNumberEditText);
        isEditTextLegit(mPhoneNumber.length() < 10, "מספר טלפון לא תקני", phoneNumberEditText);


        //creating an object for the callbacks from the sms verification code
        PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
            //when the code was sent
            @Override
            public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
                super.onCodeSent(s, forceResendingToken);
                Toast.makeText(LogingWithPhoneActivity.this, "sent" + forceResendingToken, Toast.LENGTH_SHORT).show();
                System.out.println(forceResendingToken + "9708530250  token");
                //saving the received sent
                codeSent = s;
            }

            @Override
            public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
                System.out.println(phoneAuthCredential + "9708530250    credential");
            }

            @Override
            public void onVerificationFailed(FirebaseException e) {
                if (e instanceof FirebaseAuthInvalidCredentialsException) {
                    Toast.makeText(LogingWithPhoneActivity.this, "credential error", Toast.LENGTH_SHORT).show();
                    System.out.println((e.getMessage() + "firebase error" + "1"));
                    // ...
                } else if (e instanceof FirebaseTooManyRequestsException) {
                    Toast.makeText(LogingWithPhoneActivity.this, "too many requests error", Toast.LENGTH_SHORT).show();
                    System.out.println(e.getMessage() + "firebase error" + "2");
                } else if (e != null) {
                    Toast.makeText(LogingWithPhoneActivity.this, "firebase error", Toast.LENGTH_SHORT).show();
                    System.out.println(e.getMessage() + "firebase error" + "3");


                }
            }
        };

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

    }

}


//create a credential and check it in order to sign in the user or not
private void verifyUserCode() {
    //credential is a check to compare the code that was sent and the user input for the code
    if (recivedCodeNumber.getText().toString().length() == 0) {
        Toast.makeText(this, "נא למלא את השדה", Toast.LENGTH_SHORT).show();
    } else {
        String userEnteredCode = recivedCodeNumber.getText().toString();
        PhoneAuthCredential credential = PhoneAuthProvider.getCredential(codeSent, userEnteredCode);
        signInWithPhoneAuthCredential(credential);
    }

}

//to sign in the user with the credential's (see verifyUserCode method)
private void signInWithPhoneAuthCredential(final PhoneAuthCredential credential) {
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    //   if (task.isSuccessful()) {
                    if (true) {
                        // TODO: 23/10/2018 after solving the problem with the document creation - un comment line 231 and regiser the us
                        //the code was correct and we can sign in the  user
                        //  Toast.makeText(LogingWithPhoneActivity.this, "הקוד שהוכנס נכון לבצע הץחברות", Toast.LENGTH_SHORT)
                        //        .show();
                        //  mAuth.signInWithCredential(credential);
                        sp.edit().putBoolean("logged", true).apply();


                    } else {
                        //the user entered invalid code
                        if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
                            Toast.makeText(LogingWithPhoneActivity.this, "הקוד שהוכנס שגוי", Toast.LENGTH_SHORT).show();
                        }
                    }
                }
            });
}

1 个答案:

答案 0 :(得分:1)

这很简单,在firebase控制台中转到“身份验证”选项卡,然后转到“登录方法”选项卡,插入数字并选择验证码,现在您可以测试该数字,并且拥有验证码picture for example