java - 如何测试 Firebase 白名单电话号码
问题描述
从文档中我了解到我无法将真实电话号码添加到我的白名单中:
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();
}
}
}
});
}
解决方案
这很简单,在firebase控制台中转到身份验证选项卡,现在转到登录方法选项卡,插入号码并选择验证码,现在你可以测试这个号码并且你有验证码图片例如
推荐阅读
- python - 简单的 Python Nest For 循环会耗尽内存
- javascript - 如果我在(Promise.all)函数中设置返回数据的状态,则会导致无限循环
- python - 如何在猜谜游戏中创建猜测计数器
- javascript - javascript最不常见子序列,实现缓存
- sql-server - 由于字段长度,在链接表上插入(从 MS Access 到 SQL Server)失败
- sql - 使用 LIKE 关键字了解索引性能
- google-apps-script - 从谷歌表到日历的时区差异
- html - 扩展引导页面内容的侧菜单行
- api-key - 使用 API 密钥在 Google Cloud Run 上获得 403 Forbidden
- javascript - Vue:是否可以导入仅适用于该组件的 js