Skip to content

Third-party auth

Keep your identity provider and let your users call Base with the token their provider already gave them. Base checks the token against the provider’s public keys (JWKS). Row level security reads its claims with auth.jwt(), exactly like a Base token. The same token works for the Data API, Storage, Realtime and Edge Functions.

This is different from a social or OIDC sign-in: there the provider signs users into Base, which creates a Base user. With third-party auth no Base user is created.

In the dashboard, open Authentication → Third-party auth → Add issuer, pick your provider (the fields are prefilled), save, then use Test issuer with a real token.

Provider Issuer Audience
Clerk https://<instance>.clerk.accounts.dev session tokens carry no aud: set the audience claim to azp and list your app origins
Auth0 https://<tenant>.auth0.com/ the API identifier
Firebase Auth https://securetoken.google.com/<project-id> your Firebase project id
Amazon Cognito https://cognito-idp.<region>.amazonaws.com/<pool-id> the app client id (aud for ID tokens, client_id for access tokens)
WorkOS https://api.workos.com/user_management/<client-id> as shown in your tokens
Any OIDC issuer its iss its audience

You give Base the issuer (the exact iss of the tokens), the JWKS URL, and the audiences you accept. An audience is required unless you tick “Accept any audience”, which you should only do for an issuer used by this project alone.

Mapping options: which claim becomes sub; whether sub stays the provider’s text id or becomes a stable uuid (so auth.uid() works); a claim and a value map that choose authenticated, anon or an app role (app_<slug>); and which claims to keep. A claim value that names a database role directly (service_role, postgres, app_crm and so on) is refused instead of falling back to the default role.

import { createClient } from '@potalab/base'
const base = createClient({
url,
key, // publishable key
// called before each request and when the Realtime socket connects
accessToken: async () => (await clerk.session?.getToken()) ?? null,
})
const { data } = await base.from('todos').select('*')
await base.storage.from('avatars').upload('me.png', file)

Request the provider token fresh each time: providers issue short-lived tokens. When one expires the call answers bad_jwt, the SDK asks your accessToken function again and retries once.

The claims of the provider’s token are at the top level of auth.jwt(), next to role = authenticated.

-- the provider's user id is text: compare as text
create policy "own rows" on public.todos for select to authenticated
using (user_id = (select auth.jwt() ->> 'sub'));
-- any claim your provider adds
create policy "org members" on public.projects for select to authenticated
using (org_id = (select auth.jwt() ->> 'org_id'));
-- tell external callers apart
select auth.jwt() ->> 'ext_provider'; -- 'clerk' (null for a normal Base user)

auth.uid() raises for an id that is not a uuid; choose the uuid subject format if you need it (the original id stays in ext_sub).

  • Only issuers you list are trusted. The signature is verified with that issuer’s keys, with an allowlist of asymmetric algorithms (never none or HS*).
  • exp is required, nbf is honoured, with a configurable clock skew (60 s by default). The audience is checked on the claim you choose.
  • Keys are cached for an hour and refreshed once when an unknown key id appears (at most every 30 seconds), so provider key rotation needs no action. The JWKS URL must be public https; private addresses are refused.
  • Removing an issuer stops new tokens at once. Tokens already accepted live until they expire (minutes at most).

Self-hosting: the Data Router and Realtime ask core-api to verify unknown tokens with the internal token they already use to wake sleeping projects, so no extra setup is needed with the standard Compose files. See Self-hosting upgrades for versions.