You can let your users authenticate with Firebase using their Facebook accounts by integrating Facebook Login into your app.
- Ensure you have setup Firebase in your application
- 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
- 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.
In order to sign in using Facebook you will need to integrate Facebook Login. You can do this using the Facebook API native extension. The following guide uses this ANE however you can use any method you currently have to attain the Facebook access token.
Firstly, integrate Facebook in your application by following the steps outlined in the FacebookAPI ANE documentation, this includes setting up your Facebook application in the Facebook developers site and initialising the Facebook application using
When you are logging in your users, you must ensure that you request at least the
It is also useful to check if there is already a session opened for the user, in which case you should be able to grab the access token immediately.
Once you have logged in your user into Facebook you can use the Facebook Access Token to authenticate your user with Firebase. You will use the access token to create an
AuthCredential that you can pass to the
To create an
AuthCredential for Facebook use the
The passs this to
signInWithCredential method will return the
For example, after acquiring the access token from Facebook:
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 the
In your Firebase Realtime Database and Cloud Storage Security Rules, you can get the signed-in
user's unique user ID from the auth variable, and use it to control what data a user can access.
You can allow users to sign in to your app using multiple authentication providers by linking
auth provider credentials to an existing user account.
To sign out a user, call