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
- 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).
- Add a new Third-party Auth integration in your project's Authentication settings.
- Assign the
role: 'authenticated'
custom claim to all JWTs by using an Auth0 Action. - Finally setup the Supabase client in your application.
Setup the Supabase client library
_21import { createClient } from '@supabase/supabase-js'_21import Auth0Client from '@auth0/auth0-spa-js'_21_21const auth0 = new Auth0Client({_21 domain: '<AUTH0_DOMAIN>',_21 clientId: '<AUTH0_CLIENT_ID>',_21 authorizationParams: {_21 redirect_uri: '<MY_CALLBACK_URL>',_21 },_21})_21_21const supabase = createClient('https://<supabase-project>.supabase.co', 'SUPABASE_ANON_KEY', {_21 accessToken: async () => {_21 const accessToken = await auth0.getTokenSilently()_21_21 // Alternatively you can use (await auth0.getIdTokenClaims()).__raw to_21 // use an ID token instead._21_21 return accessToken_21 },_21})
Add a new Third-Party Auth integration to your project
In the dashboard navigate to your project's Authentication settings 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:
_10[auth.third_party.auth0]_10enabled = true_10tenant = "<id>"_10tenant_region = "<region>" # if your tenant has a region
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.
A recommended approach to do this is to configure the onExecutePostLogin
Auth0 Action which will add the custom claim:
_10exports.onExecutePostLogin = async (event, api) => {_10 api.accessToken.setCustomClaim('role', 'authenticated')_10}
Limitations
At this time, Auth0 tenants with the following signing algorithms are not supported:
- HS256 (HMAC with SHA-256) -- also known as symmetric JWTs
- PS256 (RSA-PSS with SHA-256)