On theSign in methodtab, enable theFacebooksign-in
method and specify theApp IDandApp Secretyou 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 URIsin your Facebook app's settings page on theFacebook for Developerssite in theProduct Settings > Facebook Loginconfig.
In yourmodule (app-level) Gradle file(usually<project>/<app-module>/build.gradle.ktsor<project>/<app-module>/build.gradle),
add the dependency for theFirebase Authenticationlibrary for Android. We recommend using theFirebase Android BoMto control library versioning.
dependencies{// Import theBoMfor the Firebase platformimplementation(platform("com.google.firebase:firebase-bom:34.4.0"))// Add the dependency for theFirebase Authenticationlibrary// 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 usemultipleFirebase libraries in your app, we strongly
recommend using theBoMto manage library versions, which ensures that all versions are
compatible.
dependencies{// Add the dependency for theFirebase Authenticationlibrary// 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 thedeveloper's documentation. When you configure theLoginButtonorLoginManagerobject, 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)}
// 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);}
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)}
@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 theLoginButton'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:
Kotlin
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)}}}
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);}}});}
If the call tosignInWithCredentialsucceeds, 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 and
linked to the credentials—that is, the user name and password, phone
number, or auth provider information—the user signed in with. This new
account is stored as part of your Firebase project, and can be used to identify
a 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 theFirebaseUserobject. SeeManage Users.
In yourFirebase Realtime DatabaseandCloud StorageSecurity Rules, you can
get the signed-in user's unique user ID from theauthvariable,
and use it to control what data a user can access.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-10-28 UTC."],[],[]]