
# 

Auth0

## 

Use Auth0 with your Supabase project

* * *

Auth0 can be used as a third-party authentication provider alongside Supabase Auth, or standalone, with your Supabase project.

## Getting started[#](#getting-started)

1.  First you need to add an integration to connect your Supabase project with your Auth0 tenant. You will need your tenant ID (and in some cases region ID).
2.  Add a new Third-party Auth integration in your project's [Authentication settings](/dashboard/project/_/auth/third-party).
3.  Assign the `role: 'authenticated'` custom claim to all JWTs by using an Auth0 Action.
4.  Finally setup the Supabase client in your application.

## Setup the Supabase client library[#](#setup-the-supabase-client-library)

```
1import { createClient } from '@supabase/supabase-js'2import { createAuth0Client } from '@auth0/auth0-spa-js'34const auth0 = await createAuth0Client({5  domain: '<AUTH0_DOMAIN>',6  clientId: '<AUTH0_CLIENT_ID>',7  authorizationParams: {8    redirect_uri: '<MY_CALLBACK_URL>',9  },10})1112const supabase = createClient(13  'https://<supabase-project>.supabase.co',14  'SUPABASE_PUBLISHABLE_KEY',15  {16    accessToken: async () => {17      // Use the ID token which reliably includes custom claims.18      const idToken = (await auth0.getIdTokenClaims())?.__raw19      if (!idToken) throw new Error('Missing ID token')20      return idToken21    },22  }23)
```

## Add a new Third-Party Auth integration to your project[#](#add-a-new-third-party-auth-integration-to-your-project)

In the dashboard navigate to your project's [Authentication settings](/dashboard/project/_/auth/third-party) and find the Third-Party Auth section to add a new integration.

In the CLI add the following config to your `supabase/config.toml` file:

```
1[auth.third_party.auth0]2enabled = true3tenant = "<id>"4tenant_region = "<region>" # if your tenant has a region
```

## Use an Auth0 Action to assign the authenticated role[#](#use-an-auth0-action-to-assign-the-authenticated-role)

Your Supabase project inspects the `role` claim present in all JWTs sent to it, to assign the correct Postgres role when using the Data API, Storage or Realtime authorization.

By default, Auth0 JWTs (both access token and ID token) do not contain a `role` claim in them. If you were to send such a JWT to your Supabase project, the `anon` role would be assigned when executing the Postgres query. Most of your app's logic will be accessible by the `authenticated` role.

Configure the [`onExecutePostLogin` Auth0 Action](https://auth0.com/docs/secure/tokens/json-web-tokens/create-custom-claims#create-custom-claims) to add the custom claim to **ID tokens**:

```
1exports.onExecutePostLogin = async (event, api) => {2  api.idToken.setCustomClaim('role', 'authenticated')3}
```

Supabase requires the literal `role` claim key in the JWT. Auth0 [silently strips non-namespaced custom claims from access tokens](https://auth0.com/docs/troubleshoot/product-lifecycle/past-migrations/custom-claims-migration), so `api.accessToken.setCustomClaim('role', 'authenticated')` does not work. Use `api.idToken.setCustomClaim` and pass the ID token to Supabase as shown in the examples above.

## Limitations[#](#limitations)

At this time, Auth0 tenants with the following [signing algorithms](https://auth0.com/docs/get-started/applications/signing-algorithms) are not supported:

*   HS256 (HMAC with SHA-256) -- also known as symmetric JWTs
*   PS256 (RSA-PSS with SHA-256)
