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,738
  • FirebaseAuth.zip
    11.1 KB · Views: 1,154
Last edited:

Antonio Di Chiano

Member
Licensed User
Hi everyone, I need help from anyone, I have follow the istruction but i have an error into running phase:
---------------------------------------------------------------------------------------------------------------------------------------------------------
java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process it.uppeee.uppeee. Make sure to call FirebaseApp.initializeApp(Context) first.
---------------------------------------------------------------------------------------------------------------------------------------------------------

I don't understand where the problem is, I am a beginner with B4A, I need someone who has patience with inexperienced people like me. Thank you
 

metzeller_2013

Member
Licensed User
Longtime User
Is there a way for Email and Password Authentication in Firebase? Trying to use email and password auth with firebase storage.
 

Angel Garcia

Member
Licensed User
Is there a way for Email and Password Authentication in Firebase? Trying to use email and password auth with firebase storage.

This library don't support email, but the way i do it is with the firebase .Net library, just prepare a web page that receives the request after you confirm the email (with a code confirmation), and process the register with the email and update your database.
Regards,
 

Alexander Stolte

Expert
Licensed User
Longtime User
Is there a way for Email and Password Authentication in Firebase?
+
 

Ong Beny Hinadrayanto

Member
Licensed User
Please help i got this error when i build a sample. thanks

Logger connected to: Xiaomi Mi A2 Lite
--------- beginning of main
Copying updated assets files (2)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 27 (Main)
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.firebase.auth.FirebaseAuth.addAuthStateListener(com.google.firebase.auth.FirebaseAuth$AuthStateListener)' on a null object reference
at anywheresoftware.b4a.objects.FirebaseAuthWrapper.Initialize(FirebaseAuthWrapper.java:73)
at com.pijakpijak.firebase.main._activity_create(main.java:394)
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:144)
at com.pijakpijak.firebase.main.afterFirstLayout(main.java:105)
at com.pijakpijak.firebase.main.access$000(main.java:17)
at com.pijakpijak.firebase.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6694)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
** Activity (main) Resume **
 
Status
Not open for further replies.
Top