Easily add sign-in to your Android app with FirebaseUI

FirebaseUI is a library built on top of the Firebase Authentication SDK that provides drop-in UI flows for use in your app. FirebaseUI provides the following benefits:

  • Multiple Providers - sign-in flows for email, phone authentication, Google Sign-In, Facebook Login, and Twitter Login.
  • Account Management - flows to handle account management tasks, such as account creation and password resets.
  • Account Linking - flows to safely link user accounts across identity providers.
  • Custom Themes - customize the look of FirebaseUI to match your app. Also, because FirebaseUI is open source, you can fork the project and customize it exactly to your needs.
  • Smart Lock for Passwords - automatic integration with Smart Lock for Passwords for fast cross-device sign-in.

Before you begin

  1. Add Firebase to your Android project.

  2. Add the dependencies for FirebaseUI to your app-level build.gradle file. If you want to support sign-in with Facebook or Twitter, also include the Facebook and Twitter SDKs:

    dependencies {
        // ...
    
        compile 'com.firebaseui:firebase-ui-auth:3.1.0'
    
        // Required only if Facebook login support is required
        compile('com.facebook.android:facebook-android-sdk:4.27.0')
    
        // Required only if Twitter login support is required
        compile("com.twitter.sdk.android:twitter-core:3.0.0@aar") { transitive = true }
    }
    

    The FirebaseUI Auth SDK has transitive dependencies on the Firebase SDK and the Google Play services SDK.

  3. If you haven't yet connected your app to your Firebase project, do so from the Firebase console.

  4. In the Firebase console, open the Authentication section and enable the sign-in methods you want to support. Some sign-in methods require additional information, usually available in the service's developer console.

  5. If you support Google Sign-in and haven't yet specified your app's SHA-1 fingerprint, do so from the Settings page of the Firebase console. See Authenticating Your Client for details on how to get your app's SHA-1 fingerprint.

  6. If you support sign-in with Facebook or Twitter, add string resources to strings.xml that specify the identifying information required by each provider:

    <resources>
      <!-- Facebook application ID and custom URL scheme (app ID prefixed by 'fb'). -->
      <string name="facebook_application_id" translatable="false">YOUR_APP_ID</string>
      <string name="facebook_login_protocol_scheme" translatable="false">fbYOUR_APP_ID</string>
      <!-- Twitter consumer key and secret -->
      <string name="twitter_consumer_key" translatable="false">YOUR_CONSUMER_KEY</string>
      <string name="twitter_consumer_secret" translatable="false">YOUR_CONSUMER_SECRET</string>
    </resources>
    

Sign in

To kick off the FirebaseUI sign in flow, create a sign in intent with your preferred sign-in methods:

private static final int RC_SIGN_IN = 123;

// ...

// Choose authentication providers
List<AuthUI.IdpConfig> providers = Arrays.asList(
        new AuthUI.IdpConfig.Builder(AuthUI.EMAIL_PROVIDER).build(),
        new AuthUI.IdpConfig.Builder(AuthUI.PHONE_VERIFICATION_PROVIDER).build(),
        new AuthUI.IdpConfig.Builder(AuthUI.GOOGLE_PROVIDER).build(),
        new AuthUI.IdpConfig.Builder(AuthUI.FACEBOOK_PROVIDER).build(),
        new AuthUI.IdpConfig.Builder(AuthUI.TWITTER_PROVIDER).build());

// Create and launch sign-in intent
startActivityForResult(
    AuthUI.getInstance()
        .createSignInIntentBuilder()
        .setAvailableProviders(providers)
        .build(),
    RC_SIGN_IN);

When the sign-in flow is complete, you will receive the result in onActivityResult:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == RC_SIGN_IN) {
        IdpResponse response = IdpResponse.fromResultIntent(data);

        if (resultCode == ResultCodes.OK) {
            // Successfully signed in
            FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
            // ...
        } else {
            // Sign in failed, check response for error code
            // ...
        }
    }
 }

Sign Out

FirebaseUI provides convenience methods to sign out of Firebase Authentication as well as all social identity providers:

AuthUI.getInstance()
    .signOut(this)
    .addOnCompleteListener(new OnCompleteListener<Void>() {
        public void onComplete(@NonNull Task<Void> task) {
            // ...
        }
    });

You can also completely delete the user's account:

AuthUI.getInstance()
        .delete(this)
        .addOnCompleteListener(new OnCompleteListener<Void>() {
            @Override
            public void onComplete(@NonNull Task<Void> task) {
                // ...
            }
        });

Customization

By default FirebaseUI uses AppCompat for theming, which means it will naturally adopt the color scheme of your app. If you require further customization you can pass a theme and a logo to the sign-in Intent builder:

startActivityForResult(
    AuthUI.getInstance()
        .createSignInIntentBuilder()
        .setAvailableProviders(...)
        .setLogo(R.drawable.my_great_logo)      // Set logo drawable
        .setTheme(R.style.MySuperAppTheme)      // Set theme
        .build(),
    RC_SIGN_IN);

You can also set a custom privacy policy and terms of service:

startActivityForResult(
    AuthUI.getInstance()
        .createSignInIntentBuilder()
        .setAvailableProviders(...)
        .setTosUrl("https://superapp.example.com/terms-of-service.html")
        .setPrivacyPolicyUrl("https://superapp.example.com/privacy-policy.html")
        .build(),
    RC_SIGN_IN);

Next Steps

  • For more information on using and customizing FirebaseUI, see the README file on GitHub.
  • If you find and issue in FirebaseUI and would like to report it, use the GitHub issue tracker.

Send feedback about...

Need help? Visit our support page.