B4A Library FirebaseAuth - Authenticate your users

Discussion in 'Additional libraries, classes and official updates' started by Erel, Jun 13, 2016.

  1. Erel

    Erel Administrator Staff Member Licensed User

    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:

    [​IMG]

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

    [​IMG]

    Initialize the FirebaseAuth object and call SignInWithGoogle to sign in. Note that the user will be signed in automatically when the program restarts.
    Code:
    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/
     

    Attached Files:

    Last edited: Jul 5, 2016
  2. tufanv

    tufanv Expert Licensed User

    Incredible! İf we can add facebook for example to providers , it can be incredible x 1000
     
    Pendrush and susu like this.
  3. Douglas Farias

    Douglas Farias Expert Licensed User

    lol the google made a good changes.
    [​IMG]


    thx for this lib erel.
    i m waiting for facebook *-*
     
    luke2012 and awakenblueheart like this.
  4. Erel

    Erel Administrator Staff Member Licensed User

  5. tufanv

    tufanv Expert Licensed User

    You are the best!
     
  6. Eme Fibonacci

    Eme Fibonacci Active Member Licensed User

    if I put a question in the forum b4x in Portuguese about this library you can please answer it ? My Portuguese is better than English.
     
  7. Douglas Farias

    Douglas Farias Expert Licensed User

    Sended a private conversation with a brazilian group skype link.
     
  8. johndb

    johndb Active Member Licensed User

    Will the standard email firebase authentication with email confirmation be supported in addition to Google and Facebook?

    Thanks,

    John
     
    pedrocam likes this.
  9. Beja

    Beja Expert Licensed 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
     
  10. DonManfred

    DonManfred Expert Licensed 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.
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    Seems like they are adding this feature:
    [​IMG]

    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.
     
    Beja likes this.
  12. Leni Berry

    Leni Berry Active Member Licensed 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...
     
    Toky Olivier likes this.
  13. Erel

    Erel Administrator Staff Member Licensed User

    Check the logs and see whether there is any message.
     
  14. Beja

    Beja Expert Licensed 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.
     
  15. Leni Berry

    Leni Berry Active Member Licensed User

    here is the log (unfilter). i dont understand the log... help please ...
     

    Attached Files:

  16. Erel

    Erel Administrator Staff Member Licensed 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:

    [​IMG]
     
    Beja and johndb like this.
  17. johndb

    johndb Active Member Licensed User

    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.
     
  18. DonManfred

    DonManfred Expert Licensed User

    I guess this is wrong. You need a google account to setup your android-device
     
  19. johndb

    johndb Active Member Licensed User

    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 ;)
     
  20. Leni Berry

    Leni Berry Active Member Licensed User

    aha... it works... thank u erel...
     
Loading...