Authenticate Using Facebook Login on Android Stay organized with collections Save and categorize content based on your preferences.
You can let your users authenticate with Firebase using their Facebook accountsby integrating Facebook Login into your app.
Before you begin
If you haven't already,add Firebase to your Android project.
- On theFacebook for Developers site, get theApp ID and anApp Secret for your app.
- Enable Facebook Login:
- In theFirebase console, open theAuthentication section.
- On theSign in method tab, enable theFacebook sign-in method and specify theApp ID andApp Secret you got from Facebook.
- Then, make sure yourOAuth redirect URI (e.g.
my-app-12345.firebaseapp.com/__/auth/handler) is listed as one of yourOAuth redirect URIs in your Facebook app's settings page on theFacebook for Developers site in theProduct Settings > Facebook Login config.
In yourmodule (app-level) Gradle file(usually
<project>/<app-module>/build.gradle.ktsor<project>/<app-module>/build.gradle),add the dependency for theFirebase Authentication library for Android. We recommend using theFirebase Android BoMto control library versioning.dependencies{// Import theBoM for the Firebase platformimplementation(platform("com.google.firebase:firebase-bom:34.9.0"))// Add the dependency for theFirebase Authentication library// When using theBoM, you don't specify versions in Firebase library dependenciesimplementation("com.google.firebase:firebase-auth")}
By using theFirebase Android BoM, your app will always use compatible versions of Firebase Android libraries.
(Alternative) Add Firebase library dependencies without using theBoM
If you choose not to use theFirebase BoM, you must specify each Firebase library version in its dependency line.
Note that if you usemultiple Firebase libraries in your app, we strongly recommend using theBoM to manage library versions, which ensures that all versions are compatible.
dependencies{// Add the dependency for theFirebase Authentication library// When NOT using theBoM, you must specify versions in Firebase library dependenciesimplementation("com.google.firebase:firebase-auth:24.0.1")}
Authenticate with Firebase
- Integrate Facebook Login into your app by following the developer's documentation. When you configure the
LoginButtonorLoginManagerobject, request thepublic_profileandemailpermissions. If you integrated Facebook Login using aLoginButton, your sign-in activity has code similar to the following:Kotlin
// Initialize Facebook Login buttoncallbackManager=CallbackManager.Factory.create()buttonFacebookLogin.setReadPermissions("email","public_profile")buttonFacebookLogin.registerCallback(callbackManager,object:FacebookCallback<LoginResult>{overridefunonSuccess(loginResult:LoginResult){Log.d(TAG,"facebook:onSuccess:$loginResult")handleFacebookAccessToken(loginResult.accessToken)}overridefunonCancel(){Log.d(TAG,"facebook:onCancel")}overridefunonError(error:FacebookException){Log.d(TAG,"facebook:onError",error)}},)// ...overridefunonActivityResult(requestCode:Int,resultCode:Int,data:Intent?){super.onActivityResult(requestCode,resultCode,data)// Pass the activity result back to the Facebook SDKcallbackManager.onActivityResult(requestCode,resultCode,data)}
Java
// Initialize Facebook Login buttonmCallbackManager=CallbackManager.Factory.create();LoginButtonloginButton=findViewById(R.id.button_sign_in);loginButton.setReadPermissions("email","public_profile");loginButton.registerCallback(mCallbackManager,newFacebookCallback<LoginResult>(){@OverridepublicvoidonSuccess(LoginResultloginResult){Log.d(TAG,"facebook:onSuccess:"+loginResult);handleFacebookAccessToken(loginResult.getAccessToken());}@OverridepublicvoidonCancel(){Log.d(TAG,"facebook:onCancel");}@OverridepublicvoidonError(FacebookExceptionerror){Log.d(TAG,"facebook:onError",error);}});// ...@OverrideprotectedvoidonActivityResult(intrequestCode,intresultCode,Intentdata){super.onActivityResult(requestCode,resultCode,data);// Pass the activity result back to the Facebook SDKmCallbackManager.onActivityResult(requestCode,resultCode,data);}
- In your sign-in activity's
onCreatemethod, get the shared instance of theFirebaseAuthobject:Kotlin
privatelateinitvarauth:FirebaseAuth// ...// Initialize Firebase Authauth=Firebase.auth
Java
privateFirebaseAuthmAuth;// ...// Initialize Firebase AuthmAuth=FirebaseAuth.getInstance();
- When initializing your Activity, check to see if the user is currently signed in:
Kotlin
publicoverridefunonStart(){super.onStart()// Check if user is signed in (non-null) and update UI accordingly.valcurrentUser=auth.currentUserupdateUI(currentUser)}
Java
@OverridepublicvoidonStart(){super.onStart();// Check if user is signed in (non-null) and update UI accordingly.FirebaseUsercurrentUser=mAuth.getCurrentUser();updateUI(currentUser);}
- After a user successfully signs in, in the
LoginButton'sonSuccesscallback method, get an access token for the signed-in user, exchange it for a Firebase credential, and authenticate with Firebase using the Firebase credential:If the call toKotlin
privatefunhandleFacebookAccessToken(token:AccessToken){Log.d(TAG,"handleFacebookAccessToken:$token")valcredential=FacebookAuthProvider.getCredential(token.token)auth.signInWithCredential(credential).addOnCompleteListener(this){task->if(task.isSuccessful){// Sign in success, update UI with the signed-in user's informationLog.d(TAG,"signInWithCredential:success")valuser=auth.currentUserupdateUI(user)}else{// If sign in fails, display a message to the user.Log.w(TAG,"signInWithCredential:failure",task.exception)Toast.makeText(baseContext,"Authentication failed.",Toast.LENGTH_SHORT,).show()updateUI(null)}}}
Java
privatevoidhandleFacebookAccessToken(AccessTokentoken){Log.d(TAG,"handleFacebookAccessToken:"+token);AuthCredentialcredential=FacebookAuthProvider.getCredential(token.getToken());mAuth.signInWithCredential(credential).addOnCompleteListener(this,newOnCompleteListener<AuthResult>(){@OverridepublicvoidonComplete(@NonNullTask<AuthResult>task){if(task.isSuccessful()){// Sign in success, update UI with the signed-in user's informationLog.d(TAG,"signInWithCredential:success");FirebaseUseruser=mAuth.getCurrentUser();updateUI(user);}else{// If sign in fails, display a message to the user.Log.w(TAG,"signInWithCredential:failure",task.getException());Toast.makeText(FacebookLoginActivity.this,"Authentication failed.",Toast.LENGTH_SHORT).show();updateUI(null);}}});}
signInWithCredentialsucceeds, you can use thegetCurrentUsermethod to get the user's account data.
Next steps
After a user signs in for the first time, a new user account is created andlinked to the credentials—that is, the user name and password, phonenumber, or auth provider information—the user signed in with. This newaccount is stored as part of your Firebase project, and can be used to identifya user across every app in your project, regardless of how the user signs in.
In your apps, you can get the user's basic profile information from the
FirebaseUserobject. SeeManage Users.In yourFirebase Realtime Database andCloud StorageSecurity Rules, you can get the signed-in user's unique user ID from the
authvariable, and use it to control what data a user can access.
You can allow users to sign in to your app using multiple authenticationproviders bylinking auth provider credentials to anexisting user account.
To sign out a user, callsignOut:
Kotlin
Firebase.auth.signOut()
Java
FirebaseAuth.getInstance().signOut();
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-18 UTC.