I've implemented firebase phone authentication in my app and it's working fine when the user uses the app on the phone which the user receives the OTP on. I'm able to verify the OTP perfectly once I receive the OTP on my phone.
But, I just thought of another use case where a user might be using the app on the tablet and when he/she has to verify their mobile number in order to continue using the app. So they enter their mobile number on the tablet and receive the OTP on their phone. In this case, when they enter the OTP they received on their phone in the tablet, I'm not able to verify the OTP since the onVerificationCompleted() method holding null in place of the value.
Can anyone help handle this case gracefully?
Thank you.
In that case, you have to use the onCodeSent and onCodeAutoRetrievalTimeOut callbacks and ask the use to enter the code and initialize a PhoneAuthCredential to complete sign in.
Related
I have a use case where I need each user to be identified by a phone number, this is because my shops will need to call the users who request an order , I have followed the documentation and all the github repo with the code
Actually the code worked, and sended to me the sms to verify and all worked just fine !
Now, before release, I have just plugged another phone, requested the code to verify and the code never arrived !
I just tried in another phone with another number and also the verification code has never reached that phone either.
But I actually verified a phone number with the actual code and it works, so, why is the code not reaching my users phone ?
My use case needs this feature and if this is on Firebase side I will need to move to another service
Any suggestions ?
For testing you can use the verification code you added with the test phone number on the console.
Firebase Console Dashboard -> Authentication -> SignIn Method -> Phone -> Phone numbers for testing.
Sometimes, firebase don't need to send the otp for confirmation. it can automatically be done.
This method is called in two situations:
Instant verification: in some cases the phone number can be instantly verified without needing to send or enter a verification code.
Auto-retrieval: on some devices, Google Play services can automatically detect the incoming verification SMS and perform verification without user action. (This capability might be unavailable with some carriers.)
In either case, the user's phone number has been verified successfully, and you can use the PhoneAuthCredential object that's passed to the callback to sign in the user.
https://firebase.google.com/docs/auth/android/phone-auth#onverificationcompletedphoneauthcredential
Check out the docs for Firebase Phone Verification for Android : https://firebase.google.com/docs/auth/android/phone-auth?authuser=1#test-with-whitelisted-phone-numbers
I want to make an app in Android Studio where the user will have to register in Firebase using his mobile phone number. But the user would only be allowed to register if he verifies his phone number with the OTP sent to him via SMS.
I don't want to allow anyone with a fake phone number to register and hence I need them to verify. So is there a way to do so in Firebase?
I tried the auth.signInWithCredential() method but it seems to allow users to only sign in with an OTP. I also don't want my users to type an OTP every time they sign in. I want them to sign in using only their password and phone number.
I'm using firebase for phone number verification via sms.
This works nice when the verification is automatically done (SMS is sent and automatically app reads it and does the operations related to that the phone number has been verified).
But I'm now trying to make the verification with the code that is sent in this sms, as maybe not every user is going to be able to automatically read the sms message.
I thougt that the function PhoneAuthProvider.getInstance().verifyPhoneNumber would be overloaded with some option that would allow to send that code and perform the verification, but unless I'm missing something there doesn't seem to be a way with it.
On the other hamd I know this way of performing a verification via sent code, but it does require to sign in firebase, and I don't want that unless there's no another way, all that should happen is that the user sends its phone number along with the code and if correct, firebase sends something that is understood by the app as that the verification has been correct (no signing in anywhere).
Is there a way to do what I'm mentioning?
I have a similar problem with my new app released in Google Play Store. I just don't receive de sms code.
I mention that when I tested the app in debug mode and release mode it worked perfectly fine. The problem occurs when I download the app from Play Store.
Maybe you are right and the problem is that i didn't login user, because at this moment rules in Firebase Database are read and write == true.
Suppose I need to verify users by Firebase phone authentication.
But somehow, user is not getting otp sms. So does firebase gives the option to get the OTP by receiving call?
You can use Firebase Authentication to sign in a new user by sending an SMS message to his phone, he would then receive a verification code to his phone number via SMS which would then allow him to sign in if the code is correct. However it's not possible yet to give the user his verification code via a voice call. Maybe they will do it in a future release ? It would be great indeed !
How to test OTP verification with Appium.
I want to do OTP verification by appium can any one help me?.
Using Appium you can automate and control your app but there are certain limitations You need to understand the process of generating OTP. Whenever you do some transaction OTP will get generated and send to your Mobile device. So you can automate the process to perform such transaction. But after that to enter OTP which is in your Inbox you need to open your Inbox, Find the Message, Extract the OTP, Enter it. This is very complex process to automate using Appium.
I think the better alternative is to Set one fix OTP number for testing purpose instead of requesting OTP Real time.
You can switch between apps in Android. On sending OTP using your app, switch to android default message app and read OTP and then switch back to your test app.
driver.startActivity(AppPackageName, AppActivityName);
The above call can be used to switch between different app. Replace AppPackageName and AppActivityName with your test app package name / activity name and android default message app name respectively.
You can automate OTP validation from Appium in two ways.
By opening messages application in android and reading OTP from there.
By opening notifications and read OTP.
To open messages application we need to open the app using below code:
driver.startActivity(AppPackageName, AppActivityName);
To Read OTP from notification pane we can open notification pane using below code:
driver.openNotifications()
Now you can inspect OTP text element and read the text. For example, if your OTP text is
Your OTP is 3357
You will get otp as below:
string otp = driver.findElementByXpath("//*[contains(#text,"Your OTP is")]").getText().split(" is")[1]
Above code will return OTP into the string variable. Now you can use below code to come back to the application.
driver.navigate().back();
This solution is for Android only.
yes, i think you are right but, i need to login before use the app and login page have a OTP verification thats why i need to check OTP.
i can build a app with out OTP for testing but can not do every time because i have to test production build which are going to far user and in this build i can not hide OTP verification.
For OTP verification you can use Android messenger. Download android messenger apk, create test scrips to launch and read message using this app.
I don't know how to do for iOS, Can any one suggest here how to do for iOS based application.
Thanks,
Sadik