Files
supabase/apps/studio/components/interfaces/Auth/ThirdPartyAuthForm/IntegrationCard.tsx
Charis 395a54f2b7 feat(studio): gate jwt signing keys, legacy api keys, and third-party auth on grants (#53241)
Resolves
[FE-4732](https://linear.app/supabase/issue/FE-4732/grants-rollout-jwt-signing-keys-legacy-api-keys-and-third-party-auth).

## Changes
Gates the JWT signing keys, legacy API keys, and third-party auth
endpoints on grants instead of `unguarded.migrating`, and replaces their
V2 permission guards with `useGrant`:
- **Data layer (11 sites):** `data/jwt-signing-keys/*`,
`data/api-keys/legacy-api-keys-status-query`,
`data/api-keys/legacy-api-key-toggle-mutation`, and
`data/third-party-auth/*`. Queries become grant-gated query option
factories; mutations take the grant in their variables.
- **Consumers:** the JWT settings page, the JWT signing keys table and
its dialogs, `jwt-settings`, `ToggleLegacyApiKeys`, `Project/APIKeys`,
and the third-party auth page, form, and create dialogs. Each consumer
renders denied and error states.
- **JWT signing keys table:**
- It's gated only on the signing keys reads (`GET signing-keys` and `GET
signing-keys/legacy`, both `auth_signing_keys_read`).
- The legacy API keys status is only used by the revoke dialogs. If it
can't be read, revoking the legacy JWT secret fails closed: the user
sees the "disable legacy API keys first" warning, with copy explaining
why, instead of the confirm modal.
- **Legacy JWT secret query:** a 404 (secret not imported as a signing
key yet) resolves to `null` and shows the "Migrate JWT secret" panel.
Other errors now render an error instead of being treated as "not
migrated".
- **Write actions:**
- `getWriteGrantTooltip` moves from `APIKeys.utils` to `lib/grants` and
takes a resource noun. Disabled write actions use it to explain why
they're disabled.
- New `getWriteGrantToastMessage`: handlers that run without a grant now
show a toast instead of silently doing nothing. This includes the API
keys handlers from #52966.

## Permission changes
- **Legacy API keys toggle and status** (`GET`/`PUT
/v1/projects/{ref}/api-keys/legacy`): the guard moves from
`auth_signing_keys_read`/`_write` to the endpoint annotation,
`api_gateway_keys_read`/`_write`. The annotation was confirmed against
the backend controller (FE-4728). As a result, the JWT signing keys
table's legacy revoke check now depends on `api_gateway_keys_read`.
- **API keys last-used analytics**
(`/platform/projects/{ref}/analytics/endpoints/api_keys.last_used.otel`):
this endpoint uses legacy permissions (`analytics:Read` on `logflare`),
not FGA. Its check moves from the V2 `auth_signing_keys_read` check to
`useAsyncCheckPermissions(PermissionAction.ANALYTICS_READ, 'logflare')`.
- Every other guard already matched its annotation:
  - `auth_signing_keys_read`/`_write` for signing keys
  - `auth_config_read`/`_write` for third-party auth

## Testing
- Data layer: `jwt-signing-keys.test.ts`, `legacy-api-keys.test.ts`, and
`third-party-auth.test.ts` cover every migrated fetcher, check that
factories stay disabled without a grant, and cover legacy-key 404 vs.
500.
- `jwt-secret-keys-table/index.platform.test.tsx`:
- Legacy status denied: the table still renders, and revoking the legacy
key shows only the warning.
  - Legacy status known enabled or disabled.
  - Signing keys read denied.
  - Legacy key 404 vs. 500.
- `create-key-dialog.platform.test.tsx`: triggering create without a
grant shows the toast and sends no request.
- `ToggleLegacyApiKeys.platform.test.tsx`,
`ThirdPartyAuthForm.platform.test.tsx`, and
`settings/jwt/index.platform.test.tsx`: granted, denied, error, and
partial-permission cases.
- `lib/grants.test.ts`: the tooltip and toast helpers.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2026-11-10 15:30:58 -05:00

249 lines
7.9 KiB
TypeScript

import { CheckIcon } from 'lucide-react'
import Image from 'next/image'
import { Badge } from 'ui'
import { AWS_IDP_REGIONS } from './AwsRegionSelector'
import {
getIntegrationType,
getIntegrationTypeIcon,
getIntegrationTypeLabel,
INTEGRATION_TYPES,
} from './ThirdPartyAuthForm.utils'
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
import { ThirdPartyAuthIntegration } from '@/data/third-party-auth/integrations-query'
import { DOCS_URL } from '@/lib/constants'
interface IntegrationCardProps {
integration: ThirdPartyAuthIntegration
canUpdateConfig: boolean
/** Explains why deleting is disabled, if it is. */
deleteTooltip?: string
onDelete: () => void
}
export const getIntegrationTypeDescription = (type: INTEGRATION_TYPES) => {
switch (type) {
case 'firebase':
return (
<>
Allow users to use Supabase with Firebase project. You'll need to setup RLS policies for
all tables that you want to access with a Firebase JWT token. Additionally, you'll need to
add custom code to set the <code>authenticated</code> role to all your present and future
users. You can read more in the{' '}
<a
className="hover:decoration-primary underline hover:text-foreground transition"
href={`${DOCS_URL}/guides/auth`}
>
documentation
</a>
.
</>
)
case 'auth0':
return (
<>
Allow users to use Supabase with Auth0 project. Additional setup may be required. You can
read more in the{' '}
<a
className="hover:decoration-primary underline hover:text-foreground transition"
href={`${DOCS_URL}/guides/auth`}
>
documentation
</a>
.
</>
)
case 'awsCognito':
return (
<>
Allow users to use Supabase with an Amazon Cognito. Additional setup may be required. You
can read more in the{' '}
<a
className="hover:decoration-primary underline hover:text-foreground transition"
href={`${DOCS_URL}/guides/auth/third-party/aws-cognito`}
>
documentation
</a>
.
</>
)
case 'clerk':
return (
<>
Allow users to use Supabase with Clerk. Additional setup may be required. You can read
more in the{' '}
<a
className="hover:decoration-primary underline hover:text-foreground transition"
href={`${DOCS_URL}/guides/auth/third-party/clerk`}
>
documentation
</a>
.
</>
)
case 'workos':
return (
<>
Allow users to use Supabase with WorkOS. Additional setup may be required. You can read
more in the{' '}
<a
className="hover:decoration-primary underline hover:text-foreground transition"
href={`${DOCS_URL}/guides/auth/third-party/workos`}
>
documentation
</a>
.
</>
)
case 'custom':
default:
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>
.
</>
)
}
}
export const IntegrationTypeContent = ({
type,
integration,
}: {
type: INTEGRATION_TYPES
integration: ThirdPartyAuthIntegration
}) => {
switch (type) {
case 'firebase': {
const projectName =
integration.oidc_issuer_url?.replace('https://securetoken.google.com/', '') || ''
return (
<div className="text-sm flex flex-row gap-x-4">
<span className="text-foreground-light w-36">Firebase Project ID</span>
<span className="text-foreground">{projectName}</span>
</div>
)
}
case 'auth0':
const domainName =
integration.oidc_issuer_url?.replace('https://', '').replace('.auth0.com', '') || ''
return (
<div className="text-sm flex flex-row gap-x-4">
<span className="text-foreground-light w-36">Auth0 Domain Name</span>
<span className="text-foreground">{domainName}</span>
</div>
)
case 'awsCognito': {
const region =
integration.oidc_issuer_url?.split('.').filter((s) => AWS_IDP_REGIONS.includes(s))[0] || ''
const userPoolId =
integration.oidc_issuer_url?.split('/').filter((s) => s.startsWith(region || ''))[0] || ''
return (
<div className="text-sm flex flex-col gap-y-2">
<div className="flex flex-row gap-x-4">
<span className="text-foreground-light w-36">Region</span>
<span className="text-foreground">{region}</span>
</div>
<div className="flex flex-row gap-x-4">
<span className="text-foreground-light w-36">User Pool ID</span>
<span className="text-foreground">{userPoolId}</span>
</div>
</div>
)
}
case 'clerk':
return (
<div className="text-sm flex flex-row gap-x-4">
<span className="text-foreground-light w-36">Domain</span>
<span className="text-foreground">{integration?.oidc_issuer_url ?? ''}</span>
</div>
)
case 'workos':
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">{integration?.oidc_issuer_url ?? ''}</span>
</div>
)
case 'custom':
default:
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>
)
}
}
export const IntegrationCard = ({
integration,
canUpdateConfig,
deleteTooltip,
onDelete,
}: IntegrationCardProps) => {
const type = getIntegrationType(integration)
return (
<>
<div className="bg-surface-100 border overflow-hidden shadow-sm px-5 py-4 flex flex-row first:rounded-t-md last:rounded-b-md space-x-4">
<div className="py-1">
<Image src={getIntegrationTypeIcon(type)} width={21} height={21} alt={`${type} icon`} />
</div>
<div className="flex min-w-0 flex-1 flex-col gap-y-4 overflow-y-auto">
<div className="text-sm flex flex-col">
<span className="text-foreground">{getIntegrationTypeLabel(type)}</span>
<div className="text-foreground-lighter">{getIntegrationTypeDescription(type)}</div>
</div>
<IntegrationTypeContent type={type} integration={integration} />
<div>
{/* TODO: this should be a configure integration where it would show the sheet and the user can disable or delete the integration
but there's no "edit integration" endpoing for now. */}
<ButtonTooltip
variant="danger"
disabled={!canUpdateConfig}
onClick={() => onDelete()}
tooltip={{ content: { side: 'bottom', text: deleteTooltip } }}
>
Delete integration
</ButtonTooltip>
</div>
</div>
<div className="shrink-0">
{true ? (
<Badge className="space-x-1" variant="success">
<div className="h-3.5 w-3.5 bg-brand-default rounded-full flex justify-center items-center">
<CheckIcon className="h-2 w-2 text-background-overlay" strokeWidth={6} />
</div>
<span>Enabled</span>
</Badge>
) : (
<Badge variant="warning">
<span>Disabled</span>
</Badge>
)}
</div>
</div>
</>
)
}