> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hanko.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Sign in with Facebook

> Step-by-step guide to integrating Sign in with Facebook using Hanko. Enable secure authentication and seamless onboarding for your app's users.

<div class="hidden">
  **Hanko Facebook OAuth Integration Guide**:

  **About Hanko**:

  Hanko is a modern open source authentication solution and the fastest way you integrate passkeys, 2FA, SSO, and more—with full control over your data. Move between self-hosted and Hanko Cloud anytime. No lock-in. Just Auth how it should be: secure, user friendly, and fully yours.

  **What This Guide Covers**: This guide demonstrates how to integrate Facebook Login OAuth authentication with Hanko, enabling users to sign in using their Facebook accounts. You'll learn to create a Facebook app, configure OAuth settings, and implement Facebook authentication in your application.

  **Key Technologies**:

  * OAuth 2.0 authentication protocol
  * Facebook Login API and Graph API
  * JWT (JSON Web Tokens) for secure session management
  * Facebook App Review process
  * RESTful API integration

  **Prerequisites**:

  * Active Hanko Cloud account with a configured project
  * Facebook developer account and access to Facebook Developer Portal
  * Basic understanding of OAuth 2.0 authentication flow
  * Frontend application ready for integration

  **Tasks You'll Complete**:

  * Create and configure a Facebook application in the developer portal
  * Set up Facebook Login with required permissions and redirect URLs
  * Configure Facebook OAuth credentials in Hanko Console
  * Implement Facebook authentication in your frontend application
  * Understand Facebook app publishing requirements
</div>

## Prerequisites

Before starting this integration, ensure you have:

1. A Hanko Cloud account and project. [Set up your account here](https://docs.hanko.io/setup-hanko-cloud) if you haven't already.
2. A Facebook developer account. Visit the [Facebook developer portal](https://developers.facebook.com/) and select `Login` to create an account.

## Get your provider redirect URL

You'll need to configure a redirect URL in your Facebook application. This URL determines where Facebook redirects users after successful authentication. The redirect URL combines your Hanko API base URL with the [`/thirdparty/callback`](/api-reference/public/third-party/third-party-provider-callback) endpoint.

To find your redirect URL:

1. Sign in to [cloud.hanko.io](https://cloud.hanko.io).
2. Select your `Organization`.
3. Select your `Project`.
4. In the left sidebar, click `Settings`, then select `Social connections`.
5. Find your redirect URL in the `Redirect URL` input.

<Frame>
  <img src="https://mintcdn.com/hanko/nDll7gWf2olRVk-k/images/oauth-providers/facebook/hanko-callback-url.png?fit=max&auto=format&n=nDll7gWf2olRVk-k&q=85&s=ee34d656cdc8ca43487ee8a99786df18" alt="Hanko Redirect URL" width={500} style={{ borderRadius: "0.5rem" }} data-path="images/oauth-providers/facebook/hanko-callback-url.png" />
</Frame>

You need the redirect URL for [creating a new Facebook application](#create-a-new-facebook-application) in the next step.

## Create a Facebook application

1. Navigate to and log in to the [Facebook developer portal](https://developers.facebook.com).
2. In the top navigation, select `Apps`.
3. Click `Create app` in the center of the page or on the top right.

<Frame>
  <img src="https://mintcdn.com/hanko/nDll7gWf2olRVk-k/images/oauth-providers/facebook/facebook-dashboard.png?fit=max&auto=format&n=nDll7gWf2olRVk-k&q=85&s=69910c08fbd7ee92adaf25788ccbef16" alt="Facebook apps dashboard" width={500} style={{ borderRadius: "0.5rem" }} data-path="images/oauth-providers/facebook/facebook-dashboard.png" />
</Frame>

4. Enter your app details and click `Next`.

<Frame>
  <img src="https://mintcdn.com/hanko/nDll7gWf2olRVk-k/images/oauth-providers/facebook/facebook-create-app-details.png?fit=max&auto=format&n=nDll7gWf2olRVk-k&q=85&s=a48adf4f9fca301ebe055a0fd1c80848" alt="Facebook app details prompt on app creation" width={500} style={{ borderRadius: "0.5rem" }} data-path="images/oauth-providers/facebook/facebook-create-app-details.png" />
</Frame>

5. On the `Use cases` view, select `Authenticate and request data from users with Facebook Login`.
6. Click `Next`.

<Frame>
  <img src="https://mintcdn.com/hanko/nDll7gWf2olRVk-k/images/oauth-providers/facebook/facebook-create-app-use-cases.png?fit=max&auto=format&n=nDll7gWf2olRVk-k&q=85&s=d76b65268442677d49e1646fe938448c" alt="Facebook use cases prompt on app creation" width={500} style={{ borderRadius: "0.5rem" }} data-path="images/oauth-providers/facebook/facebook-create-app-use-cases.png" />
</Frame>

7. On the `Business` view, select `I don't want to connect a business portfolio yet` (or connect your existing business portfolio if available).
8. Click `Next`.

<Frame>
  <img src="https://mintcdn.com/hanko/nDll7gWf2olRVk-k/images/oauth-providers/facebook/facebook-create-app-business.png?fit=max&auto=format&n=nDll7gWf2olRVk-k&q=85&s=12602f5adc60a2b1b68d116631fcf153" alt="Facebook business portfolio connection prompt on app creation" width={500} style={{ borderRadius: "0.5rem" }} data-path="images/oauth-providers/facebook/facebook-create-app-business.png" />
</Frame>

9. On the `Create app` view, click `Go to dashboard`.

<Frame>
  <img src="https://mintcdn.com/hanko/nDll7gWf2olRVk-k/images/oauth-providers/facebook/facebook-create-app-finalize.png?fit=max&auto=format&n=nDll7gWf2olRVk-k&q=85&s=06c707a1753bff4d50869b791f5de7fa" alt="Facebook finalize app creation" width={500} style={{ borderRadius: "0.5rem" }} data-path="images/oauth-providers/facebook/facebook-create-app-finalize.png" />
</Frame>

10. On the app dashboard, click `Customize adding a Facebook Login button` in the `Add and customize use cases` section.

<Frame>
  <img src="https://mintcdn.com/hanko/nDll7gWf2olRVk-k/images/oauth-providers/facebook/facebook-customize-login-use-case.png?fit=max&auto=format&n=nDll7gWf2olRVk-k&q=85&s=7b024edbffcb944a30e6dd9c6083e1e2" alt="Facebook customize login use case" width={500} style={{ borderRadius: "0.5rem" }} data-path="images/oauth-providers/facebook/facebook-customize-login-use-case.png" />
</Frame>

11. In the `Customize use case` view, select `Permissions` in the left sidebar.
12. Click the `add` button for the `email` permission in the permissions table to enable email access.

<Frame>
  <img src="https://mintcdn.com/hanko/nDll7gWf2olRVk-k/images/oauth-providers/facebook/facebook-customize-login-add-email-permission.png?fit=max&auto=format&n=nDll7gWf2olRVk-k&q=85&s=706ffeac326dfde7f2728e7abea8e9e5" alt="Facebook customize login use case permissions by adding the email permission" width={500} style={{ borderRadius: "0.5rem" }} data-path="images/oauth-providers/facebook/facebook-customize-login-add-email-permission.png" />
</Frame>

13. In the `Customize use case` view, select `Settings` in the left sidebar.
14. Under `Valid OAuth Redirect URIs`, add the redirect URL you [retrieved from the Hanko Console](#get-your-provider-redirect-url).

<Frame>
  <img src="https://mintcdn.com/hanko/nDll7gWf2olRVk-k/images/oauth-providers/facebook/facebook-customize-login-settings.png?fit=max&auto=format&n=nDll7gWf2olRVk-k&q=85&s=097a3f77517051da3158b7f29934dc32" alt="Facebook customize login use case settings by adding valid OAuth redirect URLs" width={500} style={{ borderRadius: "0.5rem" }} data-path="images/oauth-providers/facebook/facebook-customize-login-settings.png" />
</Frame>

<Note>
  When testing locally, you don't need to add localhost redirect URLs as Facebook automatically allows all `http://localhost` redirects.
</Note>

## Get your client ID and secret

1. Navigate to the `App settings` > `Basic` for your app.
2. Copy the `App ID`.
3. `Show` and copy the `App Secret`.

<Frame>
  <img src="https://mintcdn.com/hanko/nDll7gWf2olRVk-k/images/oauth-providers/facebook/facebook-client-id-and-secret.png?fit=max&auto=format&n=nDll7gWf2olRVk-k&q=85&s=776c7aea3b375ae1d397494d76bcc5ba" alt="Facebook customize login use case settings by adding valid OAuth redirect URLs" width={500} style={{ borderRadius: "0.5rem" }} data-path="images/oauth-providers/facebook/facebook-client-id-and-secret.png" />
</Frame>

## Configure Facebook credentials in Hanko

1. In the Hanko Cloud Console, navigate to your project `Settings` and select `URLs`.
2. Configure a **Default Redirect URL** - the frontend URL where Hanko redirects users if authentication fails. For applications using `hanko-elements` web components, this should be the page containing the component to handle errors properly.
3. Configure your **Allowed Redirect URL**s - the frontend URLs where Hanko can redirect users after successful authentication. For `hanko-elements` applications, this should be the page containing the authentication component.

   <Note>
     The allowed redirect URL supports wildcard matching through globbing:

     * `https://*.example.com` matches `https://foo.example.com` and `https://bar.example.com`.
     * `https://foo.example.com/*` matches URLs like `https://foo.example.com/page1` and `https://foo.example.com/page2`.
     * Use \*\* to act as a super-wildcard/match-all.
   </Note>

<Frame>
  <img src="https://mintcdn.com/hanko/nDll7gWf2olRVk-k/images/oauth-providers/facebook/hanko-redirect-urls.png?fit=max&auto=format&n=nDll7gWf2olRVk-k&q=85&s=974e974560711ed3f5acf092e8f3d689" alt="Hanko Redirect URLs configuration" width={500} style={{ borderRadius: "0.5rem" }} data-path="images/oauth-providers/facebook/hanko-redirect-urls.png" />
</Frame>

4. Navigate to your project `Settings` and select `Social connections`.
5. In the `Providers` section, find `Facebook` and expand its configuration.
6. Enable the Facebook provider using the toggle switch.
7. Enter the Facebook `App ID` as the `Client ID`.
8. Enter the Facebook `App Secret` as the `Client Secret`.
9. Click `Save` to apply your configuration.

<Frame>
  <img src="https://mintcdn.com/hanko/nDll7gWf2olRVk-k/images/oauth-providers/facebook/hanko-configure-facebook-provider.png?fit=max&auto=format&n=nDll7gWf2olRVk-k&q=85&s=f2cfcdadbc9d5ebd797395f6787eb991" alt="Configure Facebook provider in Hanko Cloud social connection settings" width={500} style={{ borderRadius: "0.5rem" }} data-path="images/oauth-providers/facebook/hanko-configure-facebook-provider.png" />
</Frame>

## Implement Facebook login in your frontend

You can integrate Facebook authentication using either:

* Pre-built UI components from [`@teamhanko/hanko-elements`](https://www.npmjs.com/package/@teamhanko/hanko-elements)
* Custom implementation with [`@teamhanko/hanko-frontend-sdk`](https://www.npmjs.com/package/@teamhanko/hanko-frontend-sdk)

<Tabs>
  <Tab title="Hanko Elements">
    Follow our [quickstart guides](https://docs.hanko.io/quickstarts) to integrate the `<hanko-auth>` component from `@teamhanko/hanko-elements` into your application. Once configured, the component will automatically display a Facebook sign-in button in the login interface.

    <Note>
      Make sure to configure the page the web component is embedded on as your `error redirect URL` as well as an
      `allowed redirect URL` (see the [previous step](#configure-facebook-credentials-in-hanko)).
    </Note>

    After successful Facebook authentication, Hanko issues a session cookie and the component continues its normal flow. Authentication errors are automatically captured and displayed within the component.
  </Tab>

  <Tab title="Hanko Frontend SDK">
    For custom UI implementations, use the `@teamhanko/hanko-frontend-sdk` to handle Facebook authentication.
    Create a [`Hanko` client](https://teamhanko.github.io/hanko/jsdoc/hanko-frontend-sdk/Client.html) instance and call the
    `thirdParty.auth` method with `facebook` as the provider.

    ```js theme={null}
    import { Hanko } from "@teamhanko/hanko-frontend-sdk";

    // you can find the Hanko API URL on the dashboard of your project
    // in the Hanko Cloud Console
    const hanko = new Hanko("<your_hanko_api_url>");

    async function signInWithFacebook() {
        try {
            // the redirect url argument must be one of the allowed redirect URLs
            // configured in the previous step.
            await hanko.thirdParty.auth("facebook", "<your_redirect_url>");
        } catch (error) {
            // handle error
        }
    }
    ```

    After successful authentication, the API redirects to your specified URL with a one-time token in the query parameters. Exchange this token for a JWT using the `token.validate` method:

    ```js theme={null}
    import { Hanko } from "@teamhanko/hanko-frontend-sdk";

    const hanko = new Hanko("<your_hanko_api_url>");

        async function onLoad() {
            try {
                await hanko.token.validate();
            } catch (error) {
                // handle error
            }
                // you should now have a JWT cookie set
            }
    ```

    On successful validation, the SDK sets a JWT cookie (hanko) that enables authenticated API requests for all other SDK methods.
  </Tab>
</Tabs>

## Publish your app

After following this guide, your Facebook app will have an `Unpublished` status, which limits its usage to developers and testers. To allow all users to authenticate with Facebook, you must submit your app for Facebook's [App Review](https://developers.facebook.com/docs/resp-plat-initiatives/individual-processes/app-review) process and get it approved for public use.
