B4A Library Firebase UI Auth - a new Dimension in Authentication

This is a Wrap for the Firebase UI-bindings found at Github.

It offers Authentification using
- Google-Account (Tested)
- email and password authentification (Tested)
- Telephone-Authentification (Tested)
- Twitter (Not tested as i do not have a Twitter-Dev Account)
- Facebook (Not tested as i do not have a Facebookr-Dev Account)
- Authentification using a Custom Token generated by the FirebaseAdmin SDK (B4J Library currently in Beta)

For the last two (Twitter and Facebook) there must be made additional changes to the Manifest.

Requirements:
- B4A 7.8+
- Manifestchanges needed!
- You app needs to be AppCompat enabled (must use AppCompat)

Mandatory:
- Prepare your app to use Firebase. https://www.b4x.com/android/forum/threads/integrating-firebase-services.67692/#content
- Google Play Services Base - Snippet
- Firebase Base - Snippet
- Firebase Auth - Snippet
- Additional Manifestentries for the firebase-UI bindings

Add this line to your Manifest to define the needed Firebase UI Activities.

B4X:
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
CreateResourceFromFile(Macro, FirebaseUI.uibindings)

- Mandatory additional Jars needed to the B4A Code

B4X:
#AdditionalJar: androidx.legacy:legacy-support-core-utils
#AdditionalJar: androidx.annotation:annotation
#AdditionalJar: androidx.core:core
#AdditionalJar: androidx.appcompat:appcompat
#AdditionalJar: androidx.legacy:legacy-support-v4
#AdditionalJar: android.arch.lifecycle:extensions
#AdditionalJar: androidx.browser:browser
#AdditionalJar: androidx.cardview:cardview
#AdditionalJar: androidx.constraintlayout:constraintlayout
#AdditionalJar: com.google.android.material:material
#AdditionalJar: com.google.android.gms:play-services-auth
#AdditionalJar: com.google.firebase:firebase-core
#AdditionalJar: com.google.firebase:firebase-auth
#AdditionalJar: firebase-ui-auth-6.2.0.aar
#AdditionalJar: materialprogressbar-1.6.1.aar

#AdditionalRes: ..\res.FirebaseUI, com.firebase.ui.auth

Basically you setup the allowed Auth methods with this Code:
B4X:
    Dim ib As SignInIntentBuilder
    ib.Initialize("",fbauth.createSignInIntentBuilder)

    ib.addProvider(ib.IdpEMAIL_PROVIDER)
    ib.addProvider(ib.IdpPHONE_VERIFICATION_PROVIDER)
    ib.addProvider(ib.IdpANONYMOUS_PROVIDER)
    ib.addProvider(ib.getIdpGOOGLE_PROVIDER("xxxx-yyyy.apps.googleusercontent.com"))
    'ib.addProvider(ib.IdpTWITTER_PROVIDER)
    'ib.addProvider(ib.IdpFACEBOOK_PROVIDER)
    Dim intent As Intent
    intent = ib.setIsSmartLockEnabled2(False,True).setAvailableProviders(ib.Providerlist).setTosUrl("http://URLtoTOS").setPrivacyPolicyUrl("http://URLtoTOS").build
    StartActivity(intent)

NOTES:
- To use Google Authentification with this lib you need to provide the default_web_client id.

You can find the Value in the google-services.json

1. Open the google-services.json with Notepad++
2. Search for your apps packagename, you´ll find a snippet like this
"client_info": {
"mobilesdk_app_id": "1:888939569991:android:83f82a2b632ab8bf",
"android_client_info": {
"package_name": "de.donmanfred.fbui"
}
},
"oauth_client": [
{
"client_id": "dddd-ffff.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "de.donmanfred.fbui",
"certificate_hash": "hhhh"
}
},
{
"client_id": "xxxx-yyyy.apps.googleusercontent.com",
"client_type": 3
}
3. We are interested in the value of client_id from which client_type is 3.
4. Copy the value and use it in the getIdpGOOGLE_PROVIDER call above.

It will result in a Auth-Selection

WhatsApp Image 2017-12-23 at 08.39.48.jpeg

Using email
WhatsApp Image 2017-12-23 at 08.43.59.jpeg

Using new email:
WhatsApp Image 2017-12-23 at 08.45.26.jpeg


FirebaseUI

Author: DonManfred (wrapper)
Version: 0.6
  • FirebaseOptions
    • Functions:
      • Initialize (apiKey As String, appID As String, dbUrl As String, GcmsenderID As String, bucketID As String) As com.google.firebase.FirebaseOptions
  • FirebaseUI
    • Events:
      • AccessTokenAvailable (success As Boolean, token As String)
      • IdTokenChanged (user As FirebaseUser)
      • ResetPassword (success As Boolean)
      • SignedIn (user As FirebaseUser)
      • SignedOut()
      • TokenAvailable (user As FirebaseUser, success As Boolean, token As String)
      • UpdateEmail (success As Boolean, email As String)
      • UpdatePassword (success As Boolean, password As String)
      • UpdateProfile (success As Boolean, request As Object)
    • Functions:
      • AddIdTokenListener (listener As com.google.firebase.auth.FirebaseAuth.IdTokenListener)
      • AddListener (listener As com.google.firebase.auth.FirebaseAuth.AuthStateListener)
      • CreateIdTokenListener As com.google.firebase.auth.FirebaseAuth.IdTokenListener
      • CreateListener As com.google.firebase.auth.FirebaseAuth.AuthStateListener
      • createSignInIntentBuilder As com.firebase.ui.auth.AuthUI.SignInIntentBuilder
      • Initialize (EventName As String, defaultClient As String)
      • RemoveIdTokenListener (listener As com.google.firebase.auth.FirebaseAuth.IdTokenListener)
      • RemoveListener (listener As com.google.firebase.auth.FirebaseAuth.AuthStateListener)
      • sendPasswordResetEmail (email As String)
      • SendSigninIntent (signin As Intent)
      • signInWithCustomToken (token As String)
      • signOut
      • updateEmail (newEmail As String)
      • updatePassword (newPassword As String)
    • Properties:
      • CurrentUser As FirebaseUser [read only]
      • LanguageCode As String [write only]
  • FirebaseUser
    • Functions:
      • isAnonymous As Boolean
      • IsInitialized As Boolean
      • sendEmailVerification
    • Properties:
      • DisplayName As String [read only]
      • Email As String [read only]
      • PhoneNumber As String [read only]
      • PhotoUrl As String [read only]
      • Uid As String [read only]
  • GoogleBuilder
    • Functions:
      • BARef As GoogleBuilder
      • build As com.firebase.ui.auth.AuthUI.IdpConfig
      • DefaultWebClient (client As String) As GoogleBuilder
      • setScopes (scopes As java.util.List) As GoogleBuilder
        Set the scopes that your app will request when using Google sign-in. See all <a
        href="https://developers.google.com/identity/protocols/googlescopes">available
        scopes</a>.
        scopes: additional scopes to be requested
      • setSignInOptions (options As com.google.android.gms.auth.api.signin.GoogleSignInOptions) As GoogleBuilder
        Set the {@link GoogleSignInOptions} to be used for Google sign-in. Standard
        options like requesting the user's email will automatically be added.
        options: sign-in options
    • Properties:
      • Params As android.os.Bundle [read only]
      • ProviderId As String [write only]
  • SignInIntentBuilder
    • Functions:
      • addProvider (provider As com.firebase.ui.auth.AuthUI.IdpConfig)
      • build As Intent
      • clearProvider
      • getIdpGOOGLE_PROVIDER (client As String) As com.firebase.ui.auth.AuthUI.IdpConfig

        client:
        Return type: @return:config
      • GetIdpGOOGLE_PROVIDER2 (client As String, scopes As String()) As com.firebase.ui.auth.AuthUI.IdpConfig
      • GetIdpGOOGLE_PROVIDER3 (client As String) As com.firebase.ui.auth.AuthUI.IdpConfig
      • getResourceId (type As String, resourceName As String) As Int
      • Initialize (EventName As String, builder As com.firebase.ui.auth.AuthUI.SignInIntentBuilder)
      • IsInitialized As Boolean
      • setAlwaysShowSignInMethodScreen (alwaysShow As Boolean) As SignInIntentBuilder
      • setAvailableProviders (providers As java.util.List) As SignInIntentBuilder
      • setEmailLink (emailLink As String) As SignInIntentBuilder
      • setIsSmartLockEnabled (enabled As Boolean) As SignInIntentBuilder
      • setIsSmartLockEnabled2 (enableCredentials As Boolean, enableHints As Boolean) As SignInIntentBuilder
      • setLogo (logo As Int) As SignInIntentBuilder
      • setPrivacyPolicyUrl (privacyPolicyUrl As String) As SignInIntentBuilder
      • setTheme (theme As Int) As SignInIntentBuilder
      • setTosUrl (tosUrl As String) As SignInIntentBuilder
    • Properties:
      • IdpANONYMOUS_PROVIDER As com.firebase.ui.auth.AuthUI.IdpConfig [read only]
      • IdpEMAIL_PROVIDER As com.firebase.ui.auth.AuthUI.IdpConfig [read only]
      • IdpFACEBOOK_PROVIDER As com.firebase.ui.auth.AuthUI.IdpConfig [read only]
      • IdpGITHUB_PROVIDER As com.firebase.ui.auth.AuthUI.IdpConfig [read only]
      • IdpPHONE_VERIFICATION_PROVIDER As com.firebase.ui.auth.AuthUI.IdpConfig [read only]
      • IdpTWITTER_PROVIDER As com.firebase.ui.auth.AuthUI.IdpConfig [read only]
      • Providerlist As java.util.List [read only]

The Library is free to use. You can however donate for it if you want :)


Note to download the additional JARs and AARs from here:

 

Attachments

  • FirebaseUIV0.22.zip
    17.1 KB · Views: 649
  • FirebaseUIV0.51.zip
    18.6 KB · Views: 572
  • res.FirebaseUI.zip
    292.6 KB · Views: 659
  • FirebaseUIV0.6.zip
    20.3 KB · Views: 660
Last edited:

riccardomarchetto

Member
Licensed User
Longtime User
Hi @DonManfred,
I had a working app with your (great) FirebaseUI.
Passing to 8.3 I have now some problems like:

B4X:
java.lang.NullPointerException: Attempt to invoke virtual method java.lang.String android.content.Context.getString(int) on a null object reference

when i try to

B4X:
ib.addProvider(ib.IdpGOOGLE_PROVIDER)

it seems (with Add Watch Expression) that IdpGOOGLE_PROVIDER is empty
I updated sdk manager, libraries and manifest

Thank you in advance
R
 

johndb

Active Member
Licensed User
Longtime User
Hi @DonManfred,
I had a working app with your (great) FirebaseUI.
Passing to 8.3 I have now some problems like:

B4X:
java.lang.NullPointerException: Attempt to invoke virtual method java.lang.String android.content.Context.getString(int) on a null object reference

when i try to

B4X:
ib.addProvider(ib.IdpGOOGLE_PROVIDER)

it seems (with Add Watch Expression) that IdpGOOGLE_PROVIDER is empty
I updated sdk manager, libraries and manifest

Thank you in advance
R
This is a known issue with the Android SDK.
See this post on how to correct your problem.
https://www.b4x.com/android/forum/posts/591424/
 

Anser

Well-Known Member
Licensed User
Longtime User
I was testing an app and this was working fine. Today, I upgraded the library from v0.11 to 0.21
Now when I compile, I get the following compilation error. I beleived that I have followed then instructions

B4A Version: 8.30
Parsing code. (0.05s)
Compiling code. (0.21s)
Compiling layouts code. (0.02s)
Organizing libraries. (0.00s)
Generating R file. Error
..\res.firebaseui\layout\fui_confirmation_code_layout.xml:92: error: No resource identifier found for attribute 'barrierDirection' in package 'com.myfirebasetestapp.android'
..\res.firebaseui\layout\fui_confirmation_code_layout.xml:92: error: No resource identifier found for attribute 'constraint_referenced_ids' in package 'com.myfirebasetestapp.android'

Any idea, what is causing this error ?
 
Last edited:

Anser

Well-Known Member
Licensed User
Longtime User
Make sure to have V1.1.2 of the Constraintlayout maven installed with the B4A SDK Manager.
Thank you. That resolved the issue. It would be great if you could update the first post of this thread mentioning this as a requirement.

ConstraintLayout.PNG
 

Ivan Aldaz

Member
Licensed User
Longtime User
Hi.

I have the same error as in post #23. I have followed the instructions given by DonManfred in post #1, downloaded and unzipped all the files (FirebaseUIV0.21, res.Firebase, FirebaseUIaar and the example app FirebaseUIEx, and copied them to the respective folders. I have updated FirebaseAuth and Firebase Notifications (https://www.b4x.com/android/forum/threads/firebase-notifications-firebase-auth-issues.94200/), and all Firebase SDK entries are updated. In the manifest I've added these lines:

B4X:
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)
CreateResourceFromFile(Macro, FirebaseAnalytics.FirebaseAnalytics)
CreateResourceFromFile(Macro, FirebaseAuth.FirebaseAuth)
CreateResourceFromFile(Macro, FirebaseUI.uibindings)

...but even the example app by DonManfred doesn't work, and get the mentioned error:

B4X:
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getString(int)' on a null object reference

Removing the line
B4X:
ib.addProvider(ib.IdpGOOGLE_PROVIDER)

the app works but, obviously, doesn't show Google sign in option

I don't know if I'm missing some file not indicated in this thread, or what I'm doing wrong.

Any ideas?

EDIT: Forgot to mention that everything is done in Firebase (SHA, google_services.json, Google sign-in enabled...)
 
Last edited:

vercettyDev

Active Member
Licensed User
Longtime User
When I add this line: ib.addProvider(ib.IdpGOOGLE_PROVIDER)

I get the error: (NullPointerException) java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getString(int)' on a null object reference

I updated SDK
I updated B4A Version
I updated Libs

Firebase configured correctly.
 

DonManfred

Expert
Licensed User
Longtime User
I tried the version i had on my computer and it does work without problem. Possible that i updated the library already; don´t know.

Anyway i compiled again using a new versionnumber and updated #1 of this thread.
- Tested with Google-SignIn, eMail-SignIn and Phonenumber-SignIn,
- Download them new: FirebaseUIaar.zip, FirebaseUIEx.zip and FirebaseUIV0.22.zip.
- Make sure to have the additional Manifestentries. See example...
 
Last edited:

Ivan Aldaz

Member
Licensed User
Longtime User
Hi, and thanks @DonManfred.

With the new library and files now I reach the screen with the sign-in buttons, but when I press "Sign in with Google", and then select an account, I get a toast message saying "An unknown error occurred", a message that I assume is from the system. I've tried with FirebaseAuth and there's no problem signing with Google, so I think there must be something I haven't configured the right way, or some file I've pasted in the wrong folder. I have reviewed all the instructions you gave, and updated SDK, but still don't see where I am wrong. I will try to reinstall B4A and SDK.
 

larprogramer

Member
Licensed User
i get problem here
B4X:
B4A Version: 8.50
Parsing code.    (0.01s)
Building folders structure.    (0.01s)
Compiling code.    (0.09s)
Compiling layouts code.    (0.01s)
Organizing libraries.    (3.63s)
Generating R file.    Error
D:\Android\firebase fb\FirebaseUI\Objects\bin\extra\res1\res\values\values.xml:114: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.DayNight.DarkActionBar'.
..\res.firebaseui\values\styles.xml:9: error: Error: No resource found that matches the given name: attr 'colorAccent'.
..\res.firebaseui\values\styles.xml:7: error: Error: No resource found that matches the given name: attr 'colorPrimary'.
..\res.firebaseui\values\styles.xml:8: error: Error: No resource found that matches the given name: attr 'colorPrimaryDark'.
D:\Android\firebase fb\FirebaseUI\Objects\bin\extra\res1\res\values\values.xml:136: error: Error retrieving parent for item: No resource found that matches the given name '@style/Widget.AppCompat.Button.Colored'.
D:\Android\firebase fb\FirebaseUI\Objects\bin\extra\res1\res\values\values.xml:180: error: Error retrieving parent for item: No resource found that matches the given name 'Widget.AppCompat.Spinner.Underlined'.
D:\Android\firebase fb\FirebaseUI\Objects\bin\extra\res1\res\values\values.xml:265: error: Error retrieving parent for item: No resource found that matches the given name 'Widget.Design.TextInputLayout'.
 
Last edited:

asubias

Member
Licensed User
How to customize the UI:

You can edit the values.xml under \res.FirebaseUI\values and to add any style, you can write a new one as explined here:
https://stackoverflow.com/questions/44492655/customize-firebase-ui-auth-android

How to invoke new theme or icon from B4A:
B4X:
'FirebaseUI icon
#CustomBuildAction: 1, c:\windows\system32\cmd.exe, /c copy ..\Files\loginicon.png res\drawable\loginicon.png

ib.setTheme(ib.getResourceId("style", "LoginTheme"))
ib.setLogo(ib.getResourceId("drawable", "loginicon"))
 

Edwin Tenesaca Gomez

Member
Licensed User
Longtime User
Hi everyone,
I have a Issue implementing FirebaseUI-auth with a firebase-ui-auth-6.2.0 and com.google.firebase:firebase-auth 19.4.0
Just the example by @DonManfred in Firebase UI Auth - a new Dimension in Authentication

And I have this runtime exception

Exception:
** Activity (main) Pause, UserClosed = false **
java.lang.NoSuchFieldError: No static field Transform_android_rotation of type I in class Landroidx/constraintlayout/widget/R$styleable; or its superclasses (declaration of 'androidx.constraintlayout.widget.R$styleable' appears in /data/app/com.sanpiat.testing-TDsP_1gQuT4paCdvNFzyUA==/base.apk)
    at androidx.constraintlayout.widget.ConstraintSet$Transform.<clinit>(ConstraintSet.java:1071)
    at androidx.constraintlayout.widget.ConstraintSet$Constraint.<init>(ConstraintSet.java:1262)
    at androidx.constraintlayout.widget.ConstraintSet.clone(ConstraintSet.java:1510)
    at com.firebase.ui.auth.ui.idp.AuthMethodPickerActivity.onCreate(AuthMethodPickerActivity.java:126)
    at android.app.Activity.performCreate(Activity.java:7009)
    at android.app.Activity.performCreate(Activity.java:7000)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2742)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2872)
    at android.app.ActivityThread.-wrap11(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1595)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6543)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:440)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:810)
 

DonManfred

Expert
Licensed User
Longtime User
And I have this runtime exception
For which you should create a new thread in the questionsforum.
Posting to existing threads is a mistake.

Please post all relevant Infos. What B4A Version are you using?
If v10.2; did you setup a new SDK?
 
Top