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

Douglas Farias

Expert
Licensed User
Longtime User
Sended a private conversation with a brazilian group skype link.
 

johndb

Active Member
Licensed User
Longtime User
Will the standard email firebase authentication with email confirmation be supported in addition to Google and Facebook?

Thanks,

John
 

Beja

Expert
Licensed User
Longtime User
Hello Erel
Have 2 questions:
1- Is B4A v6 out already? my version is 5.80
2- Is signing with Google or any other account, for the user's protection only or it returns a value to me (or to the app) so I can know who logged in the app?

Thank you
 

DonManfred

Expert
Licensed User
Longtime User
Will the standard email firebase authentication with email confirmation be supported in addition to Google and Facebook?
It´s up to you to send a confirmation and handle the result of this to fullfill your requirements.
The firebase Authmechanism does not send any mail.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The firebase Authmechanism does not send any mail.
Seems like they are adding this feature:
SS-2016-06-20_08.41.37.png


1- Is B4A v6 out already? my version is 5.80
2- Is signing with Google or any other account, for the user's protection only or it returns a value to me (or to the app) so I can know who logged in the app?
1. The beta version has been released. The stable version will also be available soon.
2. It is only for your app. It is a way for your app (and complete solution) to identify the user.
 

Leni Berry

Active Member
Licensed User
Longtime User
i follow the instruction above.. but when run the apps, label contain only "Hello" string. and if i hit sign in with google button, it show choose acount, but when i choose the google account, nothing happen to the label... just disappear back to normal screen unless i hit the sign out button then label changed to Goodbye...
 

Beja

Expert
Licensed User
Longtime User
2. It is only for your app. It is a way for your app (and complete solution) to identify the user.

Thanks..
Can I understand that my app will lock itself if the user logged in with an email that's not already stored in the app (or in my server)?
If the app can not make some kind of verification against stored data (email) then I hardly understand the purpose of this feature.. please pardon my ignorance.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Can I understand that my app will lock itself if the user logged in with an email that's not already stored in the app (or in my server)?
If the app can not make some kind of verification against stored data (email) then I hardly understand the purpose of this feature.. please pardon my ignorance.
Examples:
- You want to restrict access to the online service to specific users. You can add the user id to the request and check it in the server.
- Think about any web page or application that requires signing in. This is an easy to use signing in system.

@Leni Berry
This is the relevant error:
Error description received from server: {
"error": {
"errors": [
{
"domain": "global",
"reason": "invalid",
"message": "OPERATION_NOT_ALLOWED"
}
],
"code": 400,
"message": "OPERATION_NOT_ALLOWED"
}
}

Seems like you didn't enable the service in Firebase console.
You need to enable Google:

SS-2016-06-20_13.24.24.png
 

johndb

Active Member
Licensed User
Longtime User
It´s up to you to send a confirmation and handle the result of this to fullfill your requirements.
The firebase Authmechanism does not send any mail.
Firebase has this feature so it would be useful to have it implemented in B4A. Not everyone has a google and Facebook account, especially email within business.
 

johndb

Active Member
Licensed User
Longtime User
I guess this is wrong. You need a google account to setup your android-device
Yes you are correct but you don't need a Google account to log into business services once you install the app. Many businesses have their own email addresses ;)
 

Leni Berry

Active Member
Licensed User
Longtime User
Examples:
- You want to restrict access to the online service to specific users. You can add the user id to the request and check it in the server.
- Think about any web page or application that requires signing in. This is an easy to use signing in system.

@Leni Berry
This is the relevant error:
Error description received from server: {
"error": {
"errors": [
{
"domain": "global",
"reason": "invalid",
"message": "OPERATION_NOT_ALLOWED"
}
],
"code": 400,
"message": "OPERATION_NOT_ALLOWED"
}
}

Seems like you didn't enable the service in Firebase console.
You need to enable Google:

SS-2016-06-20_13.24.24.png

aha... it works... thank u erel...
 
Status
Not open for further replies.
Top