B4A Library FirebaseAuth - Authenticate your users

Status
Not open for further replies.
This library requires B4A v6+.

It allows the users to sign in to your app with their Google account (more identity providers will be added in the future).

upload_2016-6-13_16-31-40.png


Like all Firebase services it is quite simple to integrate this service in your app.

1. Follow this tutorial and make sure to add the Firebase Auth manifest snippet: https://www.b4x.com/android/forum/threads/integrating-firebase-services.67692/

2. This service requires that the signing key SHA1 signature is set in the Firebase project settings:

SS-2016-06-13_16.36.56.png


You can find this value under Tools - Private Sign Key, in the signature field:

SS-2016-06-13_16.38.08.png


Initialize the FirebaseAuth object and call SignInWithGoogle to sign in. Note that the user will be signed in automatically when the program restarts.
B4X:
Sub Process_Globals
   Private auth As FirebaseAuth
End Sub

Sub Globals
   Private lblName As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
     auth.Initialize("auth")
   End If
   Activity.LoadLayout("1")
   If auth.CurrentUser.IsInitialized Then Auth_SignedIn(auth.CurrentUser)
End Sub

Sub btnSignIn_Click
   auth.SignInWithGoogle
End Sub

Sub btnSignOut_Click
   auth.SignOutFromGoogle
   lblName.Text = "Goodbye!"
End Sub

Sub Auth_SignedIn (User As FirebaseUser)
   Log("SignedIn: " & User.DisplayName)
   lblName.Text = "Hello: " & User.DisplayName
End Sub

Next:
- Combine Google and Facebook: https://www.b4x.com/android/forum/t...seauth-to-support-facebook.67954/#post-430482
- Server verification of signed in users: https://www.b4x.com/android/forum/t...end-authentication-for-signed-in-users.68672/

FirebaseAuth is an internal library now. It is preinstalled with the IDE.

V2.01 is attached. It adds a SignError (Error As Exception) event.
 

Attachments

  • FirebaseAuth_Example.zip
    11.7 KB · Views: 2,722
  • FirebaseAuth.zip
    11.1 KB · Views: 1,135
Last edited:

Rajesh Krishnan

Member
Licensed User
Hey Erel,
Following the steps uv given for the user authentication, on executing the firebase example gives an error telling package name doesnt match. But how would we get the package name without once running the code.
 

itgirl

Active Member
Licensed User
Longtime User
running the example using my own google-json and after changing the package name i get this error
B4X:
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 339)
android.content.res.Resources$NotFoundException: String resource ID #0x0
    at android.content.res.Resources.getText(Resources.java:1334)
    at android.content.res.Resources.getString(Resources.java:1428)
    at anywheresoftware.b4a.objects.FirebaseAuthWrapper.Initialize(FirebaseAuthWrapper.java:64)
    at natchcenter.com.refuni.main._activity_create(main.java:339)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
    at natchcenter.com.refuni.main.afterFirstLayout(main.java:102)
    at natchcenter.com.refuni.main.access$000(main.java:17)
    at natchcenter.com.refuni.main$WaitForLayout.run(main.java:80)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:5951)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)

any one has an idea whats going on ?

with mainfest set to
B4X:
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="25"/>

testing on Galaxy S4 with android 5
 

itgirl

Active Member
Licensed User
Longtime User
I don't recommend you to set the targetSdkVersion to 25. There might be side effects that you are unaware of.

It looks like a problem with google-services.json. Try to download it again.
actually it was 23 but i tried 25 to see if the error goes away , i tried to download google-services.json 3 times and the error still exists. by the way in the same project i have firebase FCM and firebase ads working like a charm just auth lib causes this error
B4X:
auth.Initialize("auth")
.
also i tried uninstall and reinstall
 

itgirl

Active Member
Licensed User
Longtime User
The json file downloaded is missing required fields.

It should include this field: "client_type": 3

Try to make a few changes in Firebase console and download a new json file.

If it doesn't help then try to create a new Firebase project.
Automated json file from firebase console is always buggy for me, changes to a project not always take effect in google-services.json :( but it always works after 2nd or 3rd download but with this auth didnt work even 4th download :/ can i edit the file manually and add the missing fields?
 

itgirl

Active Member
Licensed User
Longtime User
Confirmed , for further help any one whos facing the same issue as the one mentioned in #63 you MUST delete the whole project not the app and re create it in order to work , it's a bug reported many times in FireBase

Happy coding ;)
 

desof

Well-Known Member
Licensed User
Longtime User
Why does this happen with Facebook that some emails are not displayed?

K79JZly6C.png
 

Intiwhiz

Member
Licensed User
Dear @Erel,

I have trouble while compile the program, it show picture below

Your assistance really appriciated

Thanks
 

Attachments

  • 3rr0r.png
    3rr0r.png
    30 KB · Views: 361

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Phone sign-in method is now enabled .
Can we have a library or this one source code ?
Thanks
 
Status
Not open for further replies.
Top