Configure Login

Setup various login options in the app.

Make sure your app is configured with Firebase properly. Also make sure you have added the debug SHA-1 key for debugging and release SHA-1 key for release.

Generate Debug SHA-1 Key

  1. Select Gradle in android studio from right panel

  2. Select Your App

  3. In tasks -> android-> signingReport

  4. Double click signingReport

  5. You will find the SHA-1 fingerprint in the "Gradle Console"

    Copy this SHA-1 key and paste it in firebase console (Project Structure page).

Enable SignIn Option in Firebase Console

  1. Click on Authentication

  2. Switch to Sign-in method tab.

  3. Enable the options that you want to add to the app.

Add code to the app

  1. Go to Authentication.java

  2. Find this code

Authentication.java
private void showSignInScreen() {
        startActivityForResult(
                AuthUI.getInstance()
                        .createSignInIntentBuilder()
                        .setLogo(R.mipmap.ic_launcher)
                        .setAvailableProviders(Arrays.asList(
                                new AuthUI.IdpConfig.EmailBuilder().build(),
                                new AuthUI.IdpConfig.PhoneBuilder().build(),
                                new AuthUI.IdpConfig.GoogleBuilder().build()))
                        .build(),
                RC_SIGN_IN);
    }

This will add Email, Phone and Google sign in option to the app. You can remove / add / rearrange them to adjust the option.

Here is the code to add all the available sign in methods to the app.

Authentication.java
private void showSignInScreen() {
        startActivityForResult(
                AuthUI.getInstance()
                        .createSignInIntentBuilder()
                        .setLogo(R.mipmap.ic_launcher)
                        .setAvailableProviders(Arrays.asList(
                                new AuthUI.IdpConfig.EmailBuilder().build(),
                                new AuthUI.IdpConfig.PhoneBuilder().build(),
                                new AuthUI.IdpConfig.GoogleBuilder().build(),
                                new AuthUI.IdpConfig.FacebookBuilder().build(),
                                new AuthUI.IdpConfig.TwitterBuilder().build()))
                        .build(),
                RC_SIGN_IN);
    }

Note that if you will generate the signed APK for play store, the login will not work until you paste in the Google App Signing keys to the firebase console.

Facebook Login

  1. On the Facebook for Developers site, get the App ID and an App Secret for your app.

  2. In the Firebase console, open the Auth section.

  3. On the Sign in method tab, enable the Facebook sign-in method and specify the App ID and App Secret you got from Facebook.

  4. Then, make sure your OAuth redirect URI (e.g. my-app-12345.firebaseapp.com/__/auth/handler) is listed as one of your OAuth redirect URIs in your Facebook app's settings page on the Facebook for Developers site in the Product Settings > Facebook Login config.

You also need to generate a separate Key Hash in order to use the Facebook login using the openssl. You'll find more information about this on Facebook login Quick-start page on Facebook for developers site.

Last updated