B4A Library Firebase phone number authentication

catamitu

Member
Hi, your library is great, thank you!
I wonder if i can get an id token from firebase after authentification. Can you add it to library?
Maybe you can help me with a few lines of code as an example...
Thank You!
 

Enrico Fuoti

Active Member
Licensed User
Longtime User
Hi, your library is great, thank you!
I wonder if i can get an id token from firebase after authentification. Can you add it to library?
Maybe you can help me with a few lines of code as an example...
Thank You!
Thank you catamitu,
the token is returned by the User.Uid property in the sub authphone_phonesignedin .
I uploaded a new working version of the sample in first post.

auth sample:
'--------------------------------
Sub authphone_phonesignedin(success As Boolean, User As FirebaseAuthPhoneUser, info As String)
    If success = True Then
        Log("Phone Signed In: ")
        Activity.RemoveAllViews
        Activity.LoadLayout("main2")
        Log ("IsInitialized: " & User.IsInitialized)
        Log ("ProviderId:" & User.ProviderId)
        Log ("Uid:" & User.Uid)
        gs_signInMethod = "phoneLogin"
        save_signInMethod
        Activity.RemoveAllViews
        Activity.LoadLayout("main2")
        labelLogInMethod.Text = "Logged in with Phone number"
        LabelUser.Text =  "phone: " & gs_phoneNumber & CRLF & _
        "UID/Token" & CRLF &  User.Uid
    End If
End Sub
 

catamitu

Member
Thank you for your kindness. But not the user.id is what i need.
What i need is id token, that long long string of chars, in order to send it to my php server, where is decoded by JWT framework.
As far i understand, it is not recommended to use uid over internet, but tokenid.
I managed to do that for gauth and email/pass auth, but not for phone auth.
Thank you again for any help.
 

Enrico Fuoti

Active Member
Licensed User
Longtime User
Hello Catamitu,
I think i got what you are looking for..
I uploaded version 1.5.
I Added a new method :
currentToken()
if you call it after a successfull sign in, it fires the event:
authphone_gettoken(success As Boolean, token As String, info As String)
which returns the token.
 

catamitu

Member
Totally works! You did an excellent job with this library, sir!
Is it too much if i ask you to implement same method in email/pass option?

p.s. Please provide a PayPal account to buy you some beers
 

Enrico Fuoti

Active Member
Licensed User
Longtime User
Thank you for your kind words catamitu,
i upgraded the email/password lib. Same method and event names.
you can download it from the email/password post:
thank you for the beer, i appreciate your thought . At the moment
I don't remember my paypal account..
 

catamitu

Member
Thank you very much, sir, for your kindness. You help me a lot with your amazing project/library and i hope you will create many useful things like this, in the future.
Greetings!
 

Edwin Tenesaca Gomez

Member
Licensed User
Longtime User

Hello @Igor Sepic ,

The problem is the firebase-auth library, @Enrico Fuoti phoneauth library is based on com.google.firebase.firebase-auth 19.x.x and you may have updated the library 20.x.x

You need to install a new folder with the last SDK, and don't update the firebase-auth library

I hope it helps, best regards
 

Enrico Fuoti

Active Member
Licensed User
Longtime User
Hello Edwin,
i'm not sure to understand.. you mean he should downgrade to erel's firebaseAuth 1.9 ?
I compiled it with 2.01 and I don't get this error.
 

Edwin Tenesaca Gomez

Member
Licensed User
Longtime User
Hello Edwin,
i'm not sure to understand.. you mean he should downgrade to erel's firebaseAuth 1.9 ?
I compiled it with 2.01 and I don't get this error.
Hello @Enrico Fuoti ,

No the Erel's library 2.01 work fine, the problem google SDK library com.google.firebase.firebase-auth 20.x.x,

I assume that the Erel's library is based on the firebase version "com.google.firebase.firebase-auth 19.x.x", because when I updated to 20.x.x the problem mentioned by @Igor Sepic appeared.

By the way, @Enrico Fuoti thank you very much for your great input!
 

KZero

Active Member
Licensed User
Longtime User
Nice work Enrico, thanks for sharing


That's true I faced this issue too because I had to update the SDK after updating to B4A 10.70

there is an easier solution instead of redownloading the whole SDK again in another folder you can just make a copy the "Android-SDK\extras\b4a_remote\com\google\firebase\firebase-auth\19.2.0" folder and rename it to 20.0.4 (and the same for it's sub-files) and it will work with your current SDK , I didn't find any clean way to downgrade
don't forget to keep a copy of the original 20.0.4 folder
 

Addo

Well-Known Member
Licensed User
Longtime User
in empty new project i got

com.google.firebase.auth.FirebaseAuthException: This app is not authorized to use Firebase Authentication. Please verify that the correct package name and SHA-1 are configured in the Firebase Console. [ App validation failed ]
 

Enrico Fuoti

Active Member
Licensed User
Longtime User
Hello PassionDev,

you should make sure you have covered all the steps of Erel's Firebase auth tutorial and that your google-services.json is added to the app folder.
 

Addo

Well-Known Member
Licensed User
Longtime User
Hello PassionDev,

you should make sure you have covered all the steps of Erel's Firebase auth tutorial and that your google-services.json is added to the app folder.
I did. How ever i solved this. The issue werent in the steps. This issue any one will face it if using the new model of firebase. The issue in the firebase console you should add the fingerprint sha-1, sha-256 of the signed certificate to console
 

scsjc

Well-Known Member
Licensed User
Longtime User
Hi Enrico
I check a fail error with a B4A 12...

B4X:
java.lang.NoSuchMethodError: No virtual method verifyPhoneNumber(Ljava/lang/String;JLjava/util/concurrent/TimeUnit;Ljava/util/concurrent/Executor;Lcom/google/firebase/auth/PhoneAuthProvider$OnVerificationStateChangedCallbacks;)V in class Lcom/google/firebase/auth/PhoneAuthProvider; or its super classes (declaration of 'com.google.firebase.auth.PhoneAuthProvider' appears in base.apk!classes5.dex)
    at anywheresoftware.b4a.FirebaseAuthPhone.FirebaseAuthPhoneWrapper.startPhoneNumberVerification(FirebaseAuthPhoneWrapper.java:268)
    at com.oficinadirecta.login$ResumableSub_validatelefono.resume(login.java:6334)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:146)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
    at anywheresoftware.b4a.BA$2.run(BA.java:387)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7050)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)

i think the problem is with a new files firebase something change
know any solution?
 

Enrico Fuoti

Active Member
Licensed User
Longtime User
Hi scsjc,
I posted a new version recompiled with latest sdk.
it should work

 

scsjc

Well-Known Member
Licensed User
Longtime User
i see the changes:

B4X:
'added project atributes
#AdditionalJar: androidx.arch.core:core-runtime
#AdditionalJar: androidx.browser:browser

'added    "token as string"
Sub authphone_oncodesent(success As Boolean, verificationid As String, token As String)

'added manifest
AddApplicationText(<activity android:name="com.google.firebase.auth.internal.RecaptchaActivity"/>)

Is there anything else for the new version?
I have been testing in my app and it does not trigger... authphone_phoneverification >>> success=true


thanks
 

Enrico Fuoti

Active Member
Licensed User
Longtime User
Hello scsjc,

Have you tested it with the sample project ? , authphone_phoneverification is triggered correctly for me..
 

scsjc

Well-Known Member
Licensed User
Longtime User
Hello scsjc,

Have you tested it with the sample project ? , authphone_phoneverification is triggered correctly for me..
yes, i think the problem i haved in my project.

the captcha window, autoclose before select objects... ( anything from my app triger and close this window captcha )
is possible dissable windows captcha ?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…