Files
Danny WhiteandJoshen Lim 4dbb966b2e feat(studio): show Trusted Partner access on OAuth consent (#53583)
> [!WARNING]
> Live readiness checks require
[CTRL-2277](https://linear.app/supabase/issue/CTRL-2277) in the target
environment; production deployment is pending.

## Problem

Trusted Partner consent must explain direct database access and project
blockers before authorisation.
[DEPR-732](https://linear.app/supabase/issue/DEPR-732)

## Solution

- Show Direct database access alongside the requested permissions.
- Check selected projects, or every project page for organisation-wide
grants.
- Separate blocking issues from SSL notices; block authorisation during
loading or errors and offer retry.

| After |
| --- |
| <img width="1280" height="1323" alt="Authorize API Access Supabase"
src="https://github.com/user-attachments/assets/adb6367a-bace-4b62-81b5-68ba4c11396c"
/> |
| Consent screen with Direct database access (previously “Table data”)
and Database management |
| <img width="1280" height="1323" alt="Authorize API Access Supabase"
src="https://github.com/user-attachments/assets/0c35900c-1059-49cd-b1c5-4e0cf5441b9b"
/> |
| Selected-project blockers and the separate SSL notice |
| <img width="1280" height="1323" alt="95741"
src="https://github.com/user-attachments/assets/1fbef4f0-0433-4c93-b390-84d210dfb665"
/> |
| Organisation-wide blockers _without_ project-removal actions |

## Review instructions

1. Open the [staging consent
screen](https://studio-staging-git-dnywh-depr-732-trusted-partn-f24cfb-supabase.vercel.app/dashboard/authorize?auth_id=11666aa8-7f7e-4705-b33a-981903fd682e).
Enable `enableScopedOAuthConsent` in the dev toolbar’s **Flags** tab if
needed.
2. Open Chrome DevTools → **Network** and reload. Select the **GET**
request ending in `/platform/oauth/authorizations/{id}`.
3. Right-click that request → **Override content**. Choose a local
folder and click **Allow**. Add `database_token_access:read` and
`database_token_access:write` to `scopes`. Use only the read scope to
check read-only access. Keep every other field, save with
**Cmd/Ctrl+S**, then reload with DevTools open.
4. Select projects. Override each **GET** request ending in
`/platform/organizations/{slug}/oauth/authorizations/{id}/projects/{ref}/database-access`.
Use `{"issues":[],"enables_ssl":false}` for ready projects, then
`{"issues":[],"enables_ssl":true}` for an SSL notice. Save and reload
after each change. Check Direct database access and Database management
are separate, and SSL alone allows authorisation.
5. Change a readiness response to
`{"issues":["postgres_upgrade_required","platform_unsupported"],"enables_ssl":true}`.
Save and reload. Check blockers prevent authorisation, SSL stays
separate, and removing a blocked project clears its blockers.
6. Set `project_scoping_mode: false` in the authorisation override. Save
and reload. Check any blocked project prevents organisation-wide
authorisation, with no project-removal actions.
7. Block a database-access request in Network and reload. Check
authorisation stays disabled. Unblock it and choose **Retry checks**.
8. For a returning app, override `existing_grant.approved_scopes` in the
request ending in `/preflight`. Save and reload. Check added, removed
and unchanged permissions.
9. Disable **Sources → Overrides → Enable Local Overrides**. Repeat
ready and blocked project checks with a real staging authorisation
before approving live readiness behaviour.

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2026-12-02 16:19:30 +07:00

183 lines
5.7 KiB
TypeScript

import { OAuthScope } from '@supabase/shared-types/out/constants'
import type { Dispatch, SetStateAction } from 'react'
import { PERMISSIONS_DESCRIPTIONS } from '../OAuthApps.constants'
import { hasDirectDatabaseAccess } from '../OAuthApps.utils'
import { AccessLevelDropdown, type AccessLevel } from './AccessLevelDropdown'
import { DirectDatabaseAccess } from './DirectDatabaseAccess'
const accessLevels: AccessLevel[] = ['No access', 'Read only', 'Write', 'Read and write']
const Scope = ({
title,
description,
readScopeName,
writeScopeName,
scopes,
setScopes,
}: {
title: string
description: string
readScopeName: OAuthScope
writeScopeName: OAuthScope
scopes: OAuthScope[]
setScopes: Dispatch<SetStateAction<OAuthScope[]>>
}) => {
const hasRead = scopes.includes(readScopeName)
const hasWrite = scopes.includes(writeScopeName)
let accessLevel: AccessLevel = 'No access'
if (hasRead) accessLevel = 'Read only'
if (hasWrite) accessLevel = hasRead ? 'Read and write' : 'Write'
const handleAccessChange = (level: AccessLevel) => {
setScopes((current) => {
const next = current.filter((scope) => scope !== readScopeName && scope !== writeScopeName)
if (level === 'Read only' || level === 'Read and write') next.push(readScopeName)
if (level === 'Write' || level === 'Read and write') next.push(writeScopeName)
return next
})
}
return (
<div
className="grid grid-cols-1 items-start gap-3 p-4 sm:gap-5 sm:grid-cols-[minmax(0,1fr)_10rem]"
key={title}
>
<div className="flex min-w-0 flex-col gap-0.5">
<span className="text-sm font-medium text-foreground">{title}</span>
<span className="text-sm text-foreground-lighter capitalize-sentence">{description}</span>
</div>
<AccessLevelDropdown
permission={title}
levels={accessLevels}
value={accessLevel}
onChange={handleAccessChange}
/>
</div>
)
}
export const ScopesPanel = ({
scopes,
isDirectDatabaseAccessEligible,
isMemberBound,
setScopes,
}: {
isDirectDatabaseAccessEligible: boolean
isMemberBound: boolean
scopes: OAuthScope[]
setScopes: Dispatch<SetStateAction<OAuthScope[]>>
}) => {
const canShowDirectDatabaseAccess =
isDirectDatabaseAccessEligible || hasDirectDatabaseAccess(scopes)
return (
<div className="divide-y rounded-md border border-default">
<Scope
title="Analytics"
description={PERMISSIONS_DESCRIPTIONS.ANALYTICS}
readScopeName={OAuthScope.ANALYTICS_READ}
writeScopeName={OAuthScope.ANALYTICS_WRITE}
scopes={scopes}
setScopes={setScopes}
/>
<Scope
title="Analytics Config"
description={PERMISSIONS_DESCRIPTIONS.ANALYTICS_CONFIG}
readScopeName={OAuthScope.ANALYTICS_CONFIG_READ}
writeScopeName={OAuthScope.ANALYTICS_CONFIG_WRITE}
scopes={scopes}
setScopes={setScopes}
/>
<Scope
title="Auth"
description={PERMISSIONS_DESCRIPTIONS.AUTH}
readScopeName={OAuthScope.AUTH_READ}
writeScopeName={OAuthScope.AUTH_WRITE}
scopes={scopes}
setScopes={setScopes}
/>
<Scope
title="Database management"
description="Access database settings. Write access also allows the app to run SQL and reset the database password."
readScopeName={OAuthScope.DATABASE_READ}
writeScopeName={OAuthScope.DATABASE_WRITE}
scopes={scopes}
setScopes={setScopes}
/>
{canShowDirectDatabaseAccess && (
<DirectDatabaseAccess
isMemberBound={isMemberBound}
isEligible={isDirectDatabaseAccessEligible}
scopes={scopes}
setScopes={setScopes}
/>
)}
<Scope
title="Domains"
description={PERMISSIONS_DESCRIPTIONS.DOMAINS}
readScopeName={OAuthScope.DOMAINS_READ}
writeScopeName={OAuthScope.DOMAINS_WRITE}
scopes={scopes}
setScopes={setScopes}
/>
<Scope
title="Edge Functions"
description={PERMISSIONS_DESCRIPTIONS.EDGE_FUNCTIONS}
readScopeName={OAuthScope.EDGE_FUNCTIONS_READ}
writeScopeName={OAuthScope.EDGE_FUNCTIONS_WRITE}
scopes={scopes}
setScopes={setScopes}
/>
<Scope
title="Environment"
description={PERMISSIONS_DESCRIPTIONS.ENVIRONMENT}
readScopeName={OAuthScope.ENVIRONMENT_READ}
writeScopeName={OAuthScope.ENVIRONMENT_WRITE}
scopes={scopes}
setScopes={setScopes}
/>
<Scope
title="Organizations"
description={PERMISSIONS_DESCRIPTIONS.ORGANIZATIONS}
readScopeName={OAuthScope.ORGANIZATIONS_READ}
writeScopeName={OAuthScope.ORGANIZATIONS_WRITE}
scopes={scopes}
setScopes={setScopes}
/>
<Scope
title="Projects"
description={PERMISSIONS_DESCRIPTIONS.PROJECTS}
readScopeName={OAuthScope.PROJECTS_READ}
writeScopeName={OAuthScope.PROJECTS_WRITE}
scopes={scopes}
setScopes={setScopes}
/>
<Scope
title="REST"
description={PERMISSIONS_DESCRIPTIONS.REST}
readScopeName={OAuthScope.REST_READ}
writeScopeName={OAuthScope.REST_WRITE}
scopes={scopes}
setScopes={setScopes}
/>
<Scope
title="Secrets"
description={PERMISSIONS_DESCRIPTIONS.SECRETS}
readScopeName={OAuthScope.SECRETS_READ}
writeScopeName={OAuthScope.SECRETS_WRITE}
scopes={scopes}
setScopes={setScopes}
/>
<Scope
title="Storage"
description={PERMISSIONS_DESCRIPTIONS.STORAGE}
readScopeName={OAuthScope.STORAGE_READ}
writeScopeName={OAuthScope.STORAGE_WRITE}
scopes={scopes}
setScopes={setScopes}
/>
</div>
)
}