B4A Library Firebase phone number authentication

Here is my second lib, a wrap to integrate firebase auth phone number authentication.
It is working nicely on my app.
for reference visit: Authenticate with Firebase on Android using a Phone Number

FirebaseAuthPhone

Version: 1.9


Events:

  • phoneverification (success As Boolean, info As String)
  • phonesignedin (success As Boolean, User As FirebaseAuthPhoneUser, info As String)
  • oncodesent (success As Boolean, verificationid As String)
  • gettoken (success As Boolean, token As String, info As String)
Methods:
  • Initialize (eventName As String)
  • startPhoneNumberVerification (phoneNumber As String)
  • verifyPhoneNumberWithCode (verificationId As String, code As String)
  • currentToken ()
  • SignOut

Properties:
  • CurrentUser As FirebaseAuthPhoneUserWrapper [read only]


FirebaseAuthPhoneUser

Properties:

  • Anonymous As Boolean [read only]
  • IsInitialized As Boolean [read only]
  • ProviderData As List [read only]
  • ProviderId As String [read only]
  • Providers As List [read only]
  • Uid As String [read only]

Version1.8 released. It has been compiled with latest Firebase SDK and works with B4A 12.0+
Version1.9 released.Fixes a bug that caused application to crash when a wrong or expired code was entered.
 

Attachments

  • FirebaseAuthPhone_V1.9.zip
    13.1 KB · Views: 274
  • AuthSample.zip
    182.2 KB · Views: 265
Last edited:

hypergreatthing

Member
Licensed User
Longtime User
I'm having an issue when manually entering a sms authentication code that's wrong. I get a crash:
B4X:
com.google.android.gms.tasks.RuntimeExecutionException: com.google.firebase.auth.FirebaseAuthInvalidCredentialsException: The sms verification code used to create the phone auth credential is invalid. Please resend the verification code sms and be sure use the verification code provided by the user.

    at com.google.android.gms.tasks.zzu.getResult(com.google.android.gms:play-services-tasks@@17.2.0:15)

    at anywheresoftware.b4a.FirebaseAuthPhone.FirebaseAuthPhoneWrapper$3.onComplete(FirebaseAuthPhoneWrapper.java:338)



...

Caused by: com.google.firebase.auth.FirebaseAuthInvalidCredentialsException: The sms verification code used to create the phone auth credential is invalid. Please resend the verification code sms and be sure use the verification code provided by the user.
 

Enrico Fuoti

Active Member
Licensed User
Longtime User
I'm having an issue when manually entering a sms authentication code that's wrong. I get a crash:
B4X:
com.google.android.gms.tasks.RuntimeExecutionException: com.google.firebase.auth.FirebaseAuthInvalidCredentialsException: The sms verification code used to create the phone auth credential is invalid. Please resend the verification code sms and be sure use the verification code provided by the user.

    at com.google.android.gms.tasks.zzu.getResult(com.google.android.gms:play-services-tasks@@17.2.0:15)

    at anywheresoftware.b4a.FirebaseAuthPhone.FirebaseAuthPhoneWrapper$3.onComplete(FirebaseAuthPhoneWrapper.java:338)



...

Caused by: com.google.firebase.auth.FirebaseAuthInvalidCredentialsException: The sms verification code used to create the phone auth credential is invalid. Please resend the verification code sms and be sure use the verification code provided by the user.

Hello Hyper,
In most cases verification code is automatically verified by the system.. so i didn't actually tested the manual code insertion page.
All the phones i tried sent the code received by sms and verified automatically.
It looks like the wrapper code correctly receives the exception by Firebase in the callback event.
Did you try debugging b4a to check if the
sub authphone_phonesigned (success As Boolean, User As FirebaseAuthPhoneUser, info As String)
event is triggered ?
 

hypergreatthing

Member
Licensed User
Longtime User
Hello Hyper,
In most cases verification code is automatically verified by the system.. so i didn't actually tested the manual code insertion page.
All the phones i tried sent the code received by sms and verified automatically.
It looks like the wrapper code correctly receives the exception by Firebase in the callback event.
Did you try debugging b4a to check if the
sub authphone_phonesigned (success As Boolean, User As FirebaseAuthPhoneUser, info As String)
event is triggered ?
Yes. I have both _phonesignedin event and _phoneverification with break points after manually entering an incorrect sms. Neither are triggered, it just crashes straight away.
 

Enrico Fuoti

Active Member
Licensed User
Longtime User
I'm not able to replicate the issue,
Try this.
let me know.
 

Attachments

  • FirebaseAuthPhone_V1.3.zip
    9 KB · Views: 353

hypergreatthing

Member
Licensed User
Longtime User
I'm not able to replicate the issue,
Try this.
let me know.
That didn't seem to fix the crash.
Give me some time and i'll create a sample program that's cut down to just the issue.
Long story short, i'm developing an app that's to be deployed in Africa. For whatever reason the local telco is supplying odd sim cards that in android phones, show up as unknown phone numbers. In order to determine the phone number they have to sent a * code to the telco and it responds back with their phone number.
Because of this, i put in some logic so when PhoneID.GetLine1Number returns a empty string, it pulls up a screen that asks them to enter in the phone number manually.
Once they submit the number, i call authphone.startPhoneNumberVerification(phoneNumber). That seems to work perfectly fine and an sms is sent from firebase with the code.
If i enter in the code correctly everything works, it advances to the next screen. However if i enter in the wrong code (55555,etc) i get the crash.
I am able to replicate the same behavior with a 2nd phone i have if i pull the sim card with it returning an empty string for the GetLine1Number function.
I am using b4a 10.2 and android-28 as the platform.
 

Enrico Fuoti

Active Member
Licensed User
Longtime User
Hyper,
I may have found where the problem is. try this one.
 

Attachments

  • FirebaseAuthPhone_V1.3x.zip
    9 KB · Views: 349

hypergreatthing

Member
Licensed User
Longtime User
Hyper,
I may have found where the problem is. try this one.
Still crashes.
I'm attaching a sample program.
It should ask you to enter in your phone number. I suggest putting in an alternate number to get the code on another phone.
If you enter the code correctly in the next screen correctly you will log in without issue.
If you enter in the wrong code on purpose, a crash occurs.
I created a separate firebase app/keystore/etc so it should be all good to compile as is
 

Attachments

  • ManualPhoneLoginTest.zip
    91.1 KB · Views: 358

hypergreatthing

Member
Licensed User
Longtime User
Hello Hyper,
your test app and some good old logging, helped me to spot the problem.

see if it works ok for your project.
did you zip up the right files?
The V1.4.zip show files dated from 10/1 and when i load it into b4a it says version 1.3. It still crashes too
 

Enrico Fuoti

Active Member
Licensed User
Longtime User
Hello Igor,
I think for forum rules is better to start a new thread.
The phone number should be recognized and signed automatically, but in some phones it looks like it doesn't happen.
in such cases you have to type the phone number in a complete format including +xx country code.
 
Top