且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Android版Firebase中对电话号码进行身份验证而不发送SMS

更新时间:2023-11-30 21:37:16

如果没有SMS,似乎无法做到这一点.即使在Firebase文档中,也提到将通过发送代码通过SMS来完成. 以及如何在不使用SMS的情况下验证代码?电话号码不是您的android设备的属性.它在您的操作员的某个地方. 即使您设法以字符串形式获取电话号码并创建自己的方式来验证电话号码,该电话号码也不安全,并且会被反向工程设计所误用.

There seems no way to do that without an SMS. Even in firebase docs it's mentioned it will be done through SMS by sending a code. And how would you verify code without SMS? The phone number is not a property of your android device. It's somewhere with your operator. Even if you manage to get a phone number in a string and create your own way to verify the phone number it won't be safe and can be misused by reverser-engineering.

文档中提到了这一点.

onCodeAutoRetrievalTimeOut(String VerificationId)可选.这 在指定的超时持续时间后调用该方法 verifyPhoneNumber已通过,且没有onVerificationCompleted 首先触发.在没有SIM卡的设备上,此方法称为 立即进行,因为无法进行SMS自动检索.

onCodeAutoRetrievalTimeOut(String verificationId) Optional. This method is called after the timeout duration specified to verifyPhoneNumber has passed without onVerificationCompleted triggering first. On devices without SIM cards, this method is called immediately because SMS auto-retrieval isn't possible.

现在回到主题,这是可能的,但是在测试过程中. 您可以将号码列入白名单,并且不会通过短信发送OTP或代码. 但是,有一些条件. https://firebase.google. com/docs/auth/android/phone-auth#test-with-whitelisted-phone-numbers

Now coming back to the topic, this is possible but during testing. You can whitelist the numbers and the OTP or code via SMS won't be sent. However there are some conditions for it. https://firebase.google.com/docs/auth/android/phone-auth#test-with-whitelisted-phone-numbers

其次,您似乎遇到了删除电话号码但firebase仍运行onVerificationCmoplete的问题.尝试从身份验证"选项卡中删除用户并刷新它.而且,如果您的代码跟踪该电话号码或与该号码相关的用户数据,请确保也将其清除.

Secondly, you seem to have an issue where you delete the phone number but firebase still ran onVerificationCmoplete. Try deleting the user from the Authentication tab and refreshing it. And if your code keeps trace of the phone number or user data afiiliated with that number, make sure you clean that as well.