The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
feat(studio): add custom OIDC option to third-party auth providers (#51612)
claude[bot]4c7014745c22
diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.tsindex 169bef8b665..61ee0ae53bc 100644--- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts+++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts@@ -871,6 +871,7 @@ export const auth: NavMenuConstant = {{ name: 'Auth0', url: '/guides/auth/third-party/auth0' },{ name: 'AWS Cognito (Amplify)', url: '/guides/auth/third-party/aws-cognito' },{ name: 'WorkOS', url: '/guides/auth/third-party/workos' },+ { name: 'Custom OIDC', url: '/guides/auth/third-party/custom-oidc' },],},{diff --git a/apps/docs/content/guides/auth/third-party/custom-oidc.mdx b/apps/docs/content/guides/auth/third-party/custom-oidc.mdxnew file mode 100644index 00000000000..cc56295b4cb--- /dev/null+++ b/apps/docs/content/guides/auth/third-party/custom-oidc.mdx@@ -0,0 +1,109 @@+---+id: 'auth-third-party-custom-oidc'+title: 'Custom OIDC provider'+subtitle: 'Use any OIDC-compliant identity provider with your Supabase project'+---++Any identity provider that supports OpenID Connect (OIDC) can be used as a third-party authentication provider alongside Supabase Auth, or standalone, with your Supabase project. Use this guide for a provider that is not in the list of [supported providers](/docs/guides/auth/third-party/overview).++## Getting started++1. Check that your provider meets the [requirements](#requirements).+2. Add a Third-Party Auth integration with your provider's issuer URL in the [Dashboard](#add-the-integration-in-the-dashboard) or with the [Management API](#add-the-integration-with-the-management-api).+3. Add the `role` claim to the JWTs your provider issues.+4. Set up the Supabase client in your application.++## Requirements++Your provider must meet the [limitations](/docs/guides/auth/third-party/overview#limitations) of third-party auth:++1. It exposes an OIDC Issuer Discovery URL, served at `<issuer>/.well-known/openid-configuration`.+2. It signs JWTs with an asymmetric key and includes a `kid` header parameter. Symmetrically signed JWTs, such as HS256, are not supported.+3. Its JWTs contain a `role` claim. See [Assign the role claim](#assign-the-role-claim).++The issuer URL must use HTTPS. Your project reads the signing keys from the `jwks_uri` listed in the discovery document.++## Add the integration in the Dashboard++1. In the Dashboard, go to **Authentication** > **Sign In / Providers** > [**Third-Party Auth**](/dashboard/project/_/auth/third-party).+2. Click **Add provider** and select **Custom OIDC**.+3. Enter your provider's issuer URL in **Issuer URL**, for example `https://login.example.com`.+4. Click **Add provider**.++The provider appears in the Third-Party Auth list with its issuer URL. To remove it, delete it from the same list.++## Add the integration with the Management API++Create a [personal access token](/docs/guides/platform/personal-access-tokens), then call the [create third-party auth integration](/docs/reference/api/v1-create-project-tpa-integration) endpoint with your provider's issuer URL in the `oidc_issuer_url` field. To list or remove integrations, use the [list](/docs/reference/api/v1-list-project-tpa-integrations) and [delete](/docs/reference/api/v1-delete-project-tpa-integration) endpoints.++## Supabase CLI++Custom OIDC providers are not available in the Supabase CLI. There is no `supabase/config.toml` option for them.++## Assign the role claim++Your Supabase project inspects the `role` claim in every JWT sent to it, to assign the correct Postgres role when using the Data API, Storage or Realtime authorization. Without a `role` claim, requests run as the `anon` role.++Set `role` to `authenticated` for signed-in users. Use your provider's custom claims or token template feature to add it. See your provider's documentation for the steps.++## Set up the Supabase client library++Pass an `accessToken` async function that returns your provider's JWT for the current user, or `null` if there is no signed-in user:++```typescript+import { createClient } from '@supabase/supabase-js'++const supabase = createClient(+ 'https://<supabase-project>.supabase.co',+ 'SUPABASE_PUBLISHABLE_KEY',+ {+ accessToken: async () => {+ return getAccessTokenFromYourProvider()+ },+ }+)+```++Replace `getAccessTokenFromYourProvider` with the call your provider's SDK offers to get the current user's JWT.++## Using RLS policies++After the client sends your provider's JWT, use RLS policies to secure access to your project's database, Storage objects and Realtime channels.++### Identify the user++The `sub` claim identifies the user. `auth.uid()` casts `sub` to `uuid`, so it fails if your provider issues subjects that are not UUIDs. Read the claim directly instead:++```sql+create policy "Users can read their own rows"+ on table_name+ for select+ to authenticated+ using (user_id = (select auth.jwt()->>'sub'));+```++Here `user_id` must be a `text` column.++### Restrict access by issuer++Your project trusts every issuer you add, and `sub` values from different issuers can collide. If you use more than one issuer, or you also use Supabase Auth, add a restrictive policy that checks the `iss` claim:++```sql+create policy "Restrict access to trusted issuers"+ on table_name+ as restrictive+ to authenticated+ using (+ (auth.jwt()->>'iss' = 'https://<project-ref>.supabase.co/auth/v1')+ or+ (auth.jwt()->>'iss' = 'https://login.example.com')+ );+```++<Admonition type="danger">++Postgres has two types of policies: permissive and restrictive. This example uses a restrictive policy, so make sure you don't omit the `as restrictive` clause.++</Admonition>++For more on restrictive policies and on sharing the check across tables, Storage and Realtime, see the [Firebase Auth guide](/docs/guides/auth/third-party/firebase-auth#adding-an-extra-layer-of-security-to-your-projects-rls-policies-self-hosting-only).diff --git a/apps/docs/content/guides/auth/third-party/overview.mdx b/apps/docs/content/guides/auth/third-party/overview.mdxindex f2fcb750241..84dc91ccd0f 100644--- a/apps/docs/content/guides/auth/third-party/overview.mdx+++ b/apps/docs/content/guides/auth/third-party/overview.mdx@@ -11,6 +11,7 @@ Supabase has first-class support for these third-party authentication providers:- [Auth0](/docs/guides/auth/third-party/auth0)- [AWS Cognito (with or without AWS Amplify)](/docs/guides/auth/third-party/aws-cognito)- [WorkOS](/docs/guides/auth/third-party/workos)+- [Custom OIDC provider](/docs/guides/auth/third-party/custom-oidc), for any other provider that supports OpenID ConnectYou can use these providers alongside Supabase Auth, or on their own, to access the [Data API (REST and GraphQL)](/docs/guides/database/overview), [Storage](/docs/guides/storage), [Realtime](/docs/guides/storage) and [Functions](/docs/guides/functions) from your existing apps.diff --git a/apps/studio/components/interfaces/Auth/ThirdPartyAuthForm/AddIntegrationDropdown.tsx b/apps/studio/components/interfaces/Auth/ThirdPartyAuthForm/AddIntegrationDropdown.tsxindex e3d4bce184f..fc99b933868 100644--- a/apps/studio/components/interfaces/Auth/ThirdPartyAuthForm/AddIntegrationDropdown.tsx+++ b/apps/studio/components/interfaces/Auth/ThirdPartyAuthForm/AddIntegrationDropdown.tsx@@ -70,6 +70,7 @@ export const AddIntegrationDropdown = ({<ProviderDropdownItem type="workos" onSelectIntegrationType={onSelectIntegrationType} /><ProviderDropdownItem type="auth0" onSelectIntegrationType={onSelectIntegrationType} /><ProviderDropdownItem type="awsCognito" onSelectIntegrationType={onSelectIntegrationType} />+ <ProviderDropdownItem type="custom" onSelectIntegrationType={onSelectIntegrationType} /></DropdownMenuContent></DropdownMenu>)diff --git a/apps/studio/components/interfaces/Auth/ThirdPartyAuthForm/CreateCustomOidcDialog.test.tsx b/apps/studio/components/interfaces/Auth/ThirdPartyAuthForm/CreateCustomOidcDialog.test.tsxnew file mode 100644index 00000000000..e6d6f4d52ae--- /dev/null+++ b/apps/studio/components/interfaces/Auth/ThirdPartyAuthForm/CreateCustomOidcDialog.test.tsx@@ -0,0 +1,96 @@+import { fireEvent, screen, waitFor } from '@testing-library/react'+import userEvent from '@testing-library/user-event'+import { mockAnimationsApi } from 'jsdom-testing-mocks'+import { HttpResponse } from 'msw'+import { describe, expect, test, vi } from 'vitest'++import { CreateCustomOidcIntegrationDialog } from './CreateCustomOidcDialog'+import { customRender } from '@/tests/lib/custom-render'+import { addAPIMock } from '@/tests/lib/msw'++mockAnimationsApi()++const ISSUER_PLACEHOLDER = 'https://login.example.com'++const mockCreateIntegration = (requests: unknown[], response?: () => Response) => {+ addAPIMock({+ method: 'post',+ path: '/v1/projects/:ref/config/auth/third-party-auth',+ response:+ response ??+ (async ({ request }) => {+ requests.push(await request.json())+ return HttpResponse.json({+ id: '00000000-0000-0000-0000-000000000000',+ type: 'oidc',+ oidc_issuer_url: 'https://login.example.com',+ inserted_at: '2026-01-01T00:00:00Z',+ updated_at: '2026-01-01T00:00:00Z',+ })+ }),+ })+}++const renderDialog = () => {+ const onClose = vi.fn()+ customRender(<CreateCustomOidcIntegrationDialog visible onClose={onClose} />)+ return { onClose }+}++describe('CreateCustomOidcIntegrationDialog', () => {+ test('rejects a non-HTTPS issuer URL without calling the API', async () => {+ const requests: unknown[] = []+ mockCreateIntegration(requests)+ const { onClose } = renderDialog()++ await userEvent.type(+ screen.getByPlaceholderText(ISSUER_PLACEHOLDER),+ 'http://login.example.com'+ )+ fireEvent.click(await screen.findByRole('button', { name: 'Add provider' }))++ expect(await screen.findByText(/Enter an HTTPS URL/)).toBeInTheDocument()+ expect(requests).toEqual([])+ expect(onClose).not.toHaveBeenCalled()+ })++ test('requires an issuer URL', async () => {+ renderDialog()++ fireEvent.click(await screen.findByRole('button', { name: 'Add provider' }))++ expect(await screen.findByText('Issuer URL is required')).toBeInTheDocument()+ })++ test('trims whitespace, sends the issuer URL as typed, and closes on success', async () => {+ const requests: unknown[] = []+ mockCreateIntegration(requests)+ const { onClose } = renderDialog()++ await userEvent.type(+ screen.getByPlaceholderText(ISSUER_PLACEHOLDER),+ ' https://login.example.com/tenant/ '+ )+ fireEvent.click(await screen.findByRole('button', { name: 'Add provider' }))++ await waitFor(() => expect(onClose).toHaveBeenCalledOnce())+ expect(requests).toEqual([{ oidc_issuer_url: 'https://login.example.com/tenant/' }])+ })++ test('keeps the dialog open when the API rejects the issuer', async () => {+ mockCreateIntegration([], () =>+ HttpResponse.json({ message: 'Unable to fetch OIDC configuration' }, { status: 400 })+ )+ const { onClose } = renderDialog()++ await userEvent.type(+ screen.getByPlaceholderText(ISSUER_PLACEHOLDER),+ 'https://login.example.com'+ )+ const submit = await screen.findByRole('button', { name: 'Add provider' })+ fireEvent.click(submit)++ await waitFor(() => expect(submit).not.toBeDisabled())+ expect(onClose).not.toHaveBeenCalled()+ })+})diff --git a/apps/studio/components/interfaces/Auth/ThirdPartyAuthForm/CreateCustomOidcDialog.tsx b/apps/studio/components/interfaces/Auth/ThirdPartyAuthForm/CreateCustomOidcDialog.tsxnew file mode 100644index 00000000000..95ae57c5c42--- /dev/null+++ b/apps/studio/components/interfaces/Auth/ThirdPartyAuthForm/CreateCustomOidcDialog.tsx@@ -0,0 +1,122 @@+import { zodResolver } from '@hookform/resolvers/zod'+import { useParams } from 'common'+import { SubmitHandler, useForm } from 'react-hook-form'+import { toast } from 'sonner'+import {+ Button,+ Dialog,+ DialogContent,+ DialogFooter,+ DialogHeader,+ DialogSection,+ DialogTitle,+ Form,+ FormControl,+ FormField,+ Input,+ Separator,+} from 'ui'+import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'+import * as z from 'zod'++import { isValidOidcIssuerUrl } from './ThirdPartyAuthForm.utils'+import { useCreateThirdPartyAuthIntegrationMutation } from '@/data/third-party-auth/integration-create-mutation'++interface CreateCustomOidcIntegrationDialogProps {+ visible: boolean+ onClose: () => void+}++const FORM_ID = 'create-custom-oidc-integration-form'++const FormSchema = z.object({+ issuerUrl: z+ .string()+ .trim()+ .min(1, 'Issuer URL is required')+ .refine(isValidOidcIssuerUrl, 'Enter an HTTPS URL without a query string or fragment'),+})+type FormValues = z.infer<typeof FormSchema>++const defaultValues: FormValues = { issuerUrl: '' }++export const CreateCustomOidcIntegrationDialog = ({+ visible,+ onClose,+}: CreateCustomOidcIntegrationDialogProps) => {+ const { ref: projectRef } = useParams()++ const form = useForm<FormValues>({+ resolver: zodResolver(FormSchema),+ defaultValues,+ })++ const handleClose = () => {+ form.reset(defaultValues)+ onClose()+ }++ const { mutate: createAuthIntegration, isPending } = useCreateThirdPartyAuthIntegrationMutation({+ onSuccess: () => {+ toast.success('Custom OIDC provider added')+ handleClose()+ },+ })++ const onSubmit: SubmitHandler<FormValues> = (values) => {+ createAuthIntegration({ projectRef: projectRef!, oidcIssuerUrl: values.issuerUrl })+ }++ return (+ <Dialog open={visible} onOpenChange={(open) => !open && handleClose()}>+ <DialogContent>+ <DialogHeader>+ <DialogTitle className="truncate">Add custom OIDC provider</DialogTitle>+ </DialogHeader>+ <Separator />+ <DialogSection>+ <Form {...form}>+ <form id={FORM_ID} onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">+ <p className="text-sm text-foreground-light">+ Accept JWTs from any OpenID Connect (OIDC) provider.+ </p>+ <FormField+ control={form.control}+ name="issuerUrl"+ render={({ field }) => (+ <FormItemLayout+ label="Issuer URL"+ description={+ <>+ Signing keys are found at the issuer's{' '}+ <code className="text-code-inline">/.well-known/openid-configuration</code>+ </>+ }+ >+ <FormControl>+ <Input {...field} placeholder="https://login.example.com" />+ </FormControl>+ </FormItemLayout>+ )}+ />+ </form>+ </Form>+ </DialogSection>+ <DialogFooter>+ <Button disabled={isPending} onClick={handleClose}>+ Cancel+ </Button>+ <Button+ variant="primary"+ form={FORM_ID}+ type="submit"+ disabled={isPending}+ loading={isPending}+ >+ Add provider+ </Button>+ </DialogFooter>+ </DialogContent>+ </Dialog>+ )+}diff --git a/apps/studio/components/interfaces/Auth/ThirdPartyAuthForm/IntegrationCard.tsx b/apps/studio/components/interfaces/Auth/ThirdPartyAuthForm/IntegrationCard.tsxindex ca339c9a094..c3c5b278c90 100644--- a/apps/studio/components/interfaces/Auth/ThirdPartyAuthForm/IntegrationCard.tsx+++ b/apps/studio/components/interfaces/Auth/ThirdPartyAuthForm/IntegrationCard.tsx@@ -98,7 +98,19 @@ export const getIntegrationTypeDescription = (type: INTEGRATION_TYPES) => {case 'custom':default:- return 'Custom'+ return (+ <>+ Allow users to use Supabase with any OpenID Connect (OIDC) provider. You can read more in+ the{' '}+ <a+ className="hover:decoration-primary underline hover:text-foreground transition"+ href={`${DOCS_URL}/guides/auth/third-party/overview`}+ >+ documentation+ </a>+ .+ </>+ )}}@@ -170,7 +182,12 @@ export const IntegrationTypeContent = ({case 'custom':default:- return <>Custom</>+ return (+ <div className="text-sm flex flex-row gap-x-4">+ <span className="text-foreground-light w-36">Issuer URL</span>+ <span className="text-foreground break-all">{integration?.oidc_issuer_url ?? ''}</span>+ </div>+ )}}@@ -179,11 +196,7 @@ export const IntegrationCard = ({canUpdateConfig,onDelete,}: IntegrationCardProps) => {- let type = getIntegrationType(integration)-- if (type === 'custom') {- return null- }+ const type = getIntegrationType(integration)return (<>diff --git a/apps/studio/components/interfaces/Auth/ThirdPartyAuthForm/ThirdPartyAuthForm.utils.test.ts b/apps/studio/components/interfaces/Auth/ThirdPartyAuthForm/ThirdPartyAuthForm.utils.test.tsnew file mode 100644index 00000000000..bcb81c6fbe9--- /dev/null+++ b/apps/studio/components/interfaces/Auth/ThirdPartyAuthForm/ThirdPartyAuthForm.utils.test.ts@@ -0,0 +1,61 @@+import { describe, expect, it } from 'vitest'++import {+ getIntegrationType,+ getIntegrationTypeLabel,+ isValidOidcIssuerUrl,+} from './ThirdPartyAuthForm.utils'+import type { ThirdPartyAuthIntegration } from '@/data/third-party-auth/integrations-query'++const buildIntegration = (oidcIssuerUrl: string): ThirdPartyAuthIntegration => ({+ id: '00000000-0000-0000-0000-000000000000',+ type: 'oidc',+ oidc_issuer_url: oidcIssuerUrl,+ inserted_at: '2026-01-01T00:00:00Z',+ updated_at: '2026-01-01T00:00:00Z',+})++describe('isValidOidcIssuerUrl', () => {+ it.each([+ 'https://login.example.com',+ 'https://login.example.com/',+ 'https://example.com/realms/my-realm',+ 'https://login.example.com:8443/tenant',+ ])('accepts %s', (value) => {+ expect(isValidOidcIssuerUrl(value)).toBe(true)+ })++ it.each([+ '',+ 'login.example.com',+ 'http://login.example.com',+ 'ftp://login.example.com',+ 'https://',+ 'https://login.example.com?tenant=a',+ 'https://login.example.com/#fragment',+ 'https://user:[email protected]',+ 'not a url',+ ])('rejects %j', (value) => {+ expect(isValidOidcIssuerUrl(value)).toBe(false)+ })+})++describe('getIntegrationType', () => {+ it('detects known providers from the issuer URL', () => {+ expect(getIntegrationType(buildIntegration('https://securetoken.google.com/my-project'))).toBe(+ 'firebase'+ )+ expect(getIntegrationType(buildIntegration('https://acme.auth0.com'))).toBe('auth0')+ })++ it('falls back to custom for any other issuer', () => {+ expect(getIntegrationType(buildIntegration('https://login.example.com'))).toBe('custom')+ expect(getIntegrationType(undefined)).toBe('custom')+ })+})++describe('getIntegrationTypeLabel', () => {+ it('labels custom issuers as Custom OIDC', () => {+ expect(getIntegrationTypeLabel('custom')).toBe('Custom OIDC')+ })+})diff --git a/apps/studio/components/interfaces/Auth/ThirdPartyAuthForm/ThirdPartyAuthForm.utils.ts b/apps/studio/components/interfaces/Auth/ThirdPartyAuthForm/ThirdPartyAuthForm.utils.tsindex 349b887199d..fcc164e667d 100644--- a/apps/studio/components/interfaces/Auth/ThirdPartyAuthForm/ThirdPartyAuthForm.utils.ts+++ b/apps/studio/components/interfaces/Auth/ThirdPartyAuthForm/ThirdPartyAuthForm.utils.ts@@ -53,7 +53,7 @@ export const getIntegrationTypeLabel = (type: INTEGRATION_TYPES) => {return 'WorkOS'case 'custom':default:- return 'Custom'+ return 'Custom OIDC'}}@@ -69,9 +69,19 @@ export const getIntegrationTypeIcon = (type: INTEGRATION_TYPES) => {return `${BASE_PATH}/img/icons/clerk-icon.svg`case 'workos':return `${BASE_PATH}/img/icons/workos-icon.svg`-case 'custom':default:- return `${BASE_PATH}/img/icons/cognito-icon.svg`+ return `${BASE_PATH}/img/icons/badge-check-icon.svg`+ }+}++export const isValidOidcIssuerUrl = (value: string) => {+ if (value.includes('?') || value.includes('#')) return false++ try {+ const url = new URL(value)+ return url.protocol === 'https:' && url.hostname.length > 0 && !url.username && !url.password+ } catch {+ return false}}diff --git a/apps/studio/components/interfaces/Auth/ThirdPartyAuthForm/index.tsx b/apps/studio/components/interfaces/Auth/ThirdPartyAuthForm/index.tsxindex 25e3a15c879..03a8eaed8d2 100644--- a/apps/studio/components/interfaces/Auth/ThirdPartyAuthForm/index.tsx+++ b/apps/studio/components/interfaces/Auth/ThirdPartyAuthForm/index.tsx@@ -21,6 +21,7 @@ import { AddIntegrationDropdown } from './AddIntegrationDropdown'import { CreateAuth0IntegrationDialog } from './CreateAuth0Dialog'import { CreateAwsCognitoAuthIntegrationDialog } from './CreateAwsCognitoAuthDialog'import { CreateClerkAuthIntegrationDialog } from './CreateClerkAuthDialog'+import { CreateCustomOidcIntegrationDialog } from './CreateCustomOidcDialog'import { CreateFirebaseAuthIntegrationDialog } from './CreateFirebaseAuthDialog'import { CreateWorkOSIntegrationDialog } from './CreateWorkOSDialog'import { IntegrationCard } from './IntegrationCard'@@ -172,6 +173,11 @@ export const ThirdPartyAuthForm = () => {onClose={() => setSelectedIntegration(undefined)}/>+ <CreateCustomOidcIntegrationDialog+ visible={selectedIntegration === 'custom'}+ onClose={() => setSelectedIntegration(undefined)}+ />+<ConfirmationModalsize="medium"visible={!!selectedIntegrationForDeletion}diff --git a/apps/studio/public/img/icons/badge-check-icon.svg b/apps/studio/public/img/icons/badge-check-icon.svgnew file mode 100644index 00000000000..1620fce3f93--- /dev/null+++ b/apps/studio/public/img/icons/badge-check-icon.svg@@ -0,0 +1 @@+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="gray" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-badge-check-icon lucide-badge-check"><path d="M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z"/><path d="m9 12 2 2 4-4"/></svg>