To authenticate users with Firebase using their Facebook accounts, you can integrate Facebook Login into your app. You can integrate Facebook Login either by using the Firebase SDK to carry out the sign-in flow, or by carrying out the Facebook Login flow manually and passing the resulting access token to Firebase.
Before you begin, on the Facebook for Developers site, get the App ID and an App Secret for your app. Enable Facebook Login: In the Firebase console, open the Auth section. On the Sign in method tab, enable the Facebook sign-in method and specify the App ID and App Secret you got from Facebook.
To handle the sign-in flow with the Firebase JavaScript SDK, follow these steps:
- Create an instance of the Facebook provider object:
import { FacebookAuthProvider } from "firebase/auth";
const provider = new FacebookAuthProvider();
- Optional: Specify additional OAuth 2.0 scopes that you want to request from the authentication provider. To add a scope, call
addScope
. For example:
provider.addScope('user_birthday');
- Optional: To localize the provider's OAuth flow to the user's preferred language without explicitly passing the relevant custom OAuth parameters, update the language code on the Auth instance before starting the OAuth flow. For example:
import { getAuth } from "firebase/auth";
const auth = getAuth();
auth.languageCode = 'it';
- Optional: Specify additional custom OAuth provider parameters that you want to send with the OAuth request. To add a custom parameter, call
setCustomParameters
on the initialized provider with an object containing the key as specified by the OAuth provider documentation and the corresponding value. For example:
provider.setCustomParameters({'display': 'popup'});
You can find more information on the Firebase documentation: firebase.google.com