Skip to content
Back to catalog
Facebook

OAuth with Facebook

Authenticate users with an existing Facebook account

Facebook is Meta's social network, where people connect with friends, communities, and businesses. Facebook Login lets apps sign people in with the Facebook account they already use every day.

How does the integration work?

You can use the Facebook OAuth adapter in Appwrite Auth to let users sign in with their Facebook account. This is a common choice for consumer apps, because it saves users from creating another account and password.

Appwrite requests the email permission and stores the user's name, email, and profile picture from the Graph API. Facebook doesn't report whether the email is verified, so Appwrite stores it as unverified. If another user in your project already has that email, Appwrite redirects to your failure URL instead of signing the user in. To connect Facebook to that account, have the user sign in first and then start the OAuth flow from the browser, which links Facebook as a new identity.

How to implement

To implement the Facebook OAuth adapter in Appwrite Auth, there are several steps you must complete:

Step 1: Create an app on Meta for Developers

Go to Meta for Developers and create an app that uses Facebook Login to authenticate users. In the app's Facebook Login permissions, make sure email is included alongside the default public_profile.

Open App settings > Basic and save the App ID and App secret for later use. You'll add the redirect URI to the Facebook Login settings after you configure Appwrite in the next step.

Step 2: Add Facebook OAuth adapter to your Appwrite project

For this step, you must create an account on Appwrite Cloud or self-host Appwrite if you haven't already. In your Appwrite project, head over to the Auth page, open the Settings tab, and click Facebook under the OAuth2 Providers section.

Paste the app's credentials into the App ID and App Secret fields, turn the provider on, and click Update.

Copy the Redirect URI shown in the form. On Appwrite Cloud it looks like https://<REGION>.cloud.appwrite.io/v1/account/sessions/oauth2/callback/facebook/<PROJECT_ID>, but always copy the exact value from the Console. In your Meta app, open the Facebook Login settings and add the URI to Valid OAuth Redirect URIs under Client OAuth Settings, then save.

While your Meta app is in development mode, only people with a role on the app can sign in. Switch the app to live mode before you launch.

Step 3: Test the provider

Start a session from your app with the OAuthProvider.Facebook value. With the Web SDK:

JavaScript
import { Client, Account, OAuthProvider } from 'appwrite';
const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1')
.setProject('<PROJECT_ID>');
const account = new Account(client);
account.createOAuth2Session({
provider: OAuthProvider.Facebook,
success: 'https://example.com/success',
failure: 'https://example.com/failed',
});

Add your app's domain as a web platform in your Appwrite project so Appwrite accepts the success and failure URLs. Follow the OAuth 2 login flow for other platforms and for server-side sign-in.

Read more about Facebook and Appwrite Auth

If you would like to learn more about Facebook and Appwrite Auth, we have some resources that you should visit:

Technology Partner Program

Building on Appwrite?

Teams and developers who ship integrations, tools, or services on Appwrite can join our partner program for verified catalog placement, co-marketing, training, and engineering support.