The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
feat(studio): scoped oauth apps reconsent UI (#51078)
Gildas Garcia4bf7b164732d
diff --git a/apps/studio/components/interfaces/Database/Backups/PITR/TimezoneSelection.test.tsx b/apps/studio/components/interfaces/Database/Backups/PITR/TimezoneSelection.test.tsxindex 858d534a51b..fc3782a3231 100644--- a/apps/studio/components/interfaces/Database/Backups/PITR/TimezoneSelection.test.tsx+++ b/apps/studio/components/interfaces/Database/Backups/PITR/TimezoneSelection.test.tsx@@ -52,5 +52,5 @@ describe('TimezoneSelection', () => {expect(onSelectTimezone).toHaveBeenCalledTimes(1)expect(onSelectTimezone.mock.calls[0][0]).toBe(madridTimezone)expect(trigger).toHaveAttribute('aria-expanded', 'false')- })+ }, 10_000)})diff --git a/apps/studio/components/interfaces/Organization/OAuthApps/Consent/AuthorizingAsCard.tsx b/apps/studio/components/interfaces/Organization/OAuthApps/Consent/AuthorizingAsCard.tsxindex 7f8886d8b07..bef7263772e 100644--- a/apps/studio/components/interfaces/Organization/OAuthApps/Consent/AuthorizingAsCard.tsx+++ b/apps/studio/components/interfaces/Organization/OAuthApps/Consent/AuthorizingAsCard.tsx@@ -1,6 +1,6 @@import { LogOut } from 'lucide-react'-import { Button, Tooltip, TooltipContent, TooltipTrigger } from 'ui'+import { ButtonTooltip } from '@/components/ui/ButtonTooltip'import { OAuthAppsAuthorizeRequest } from '@/data/oauth-apps/types'export interface AuthorizingAsCardProps {@@ -23,21 +23,16 @@ export const AuthorizingAsCard = ({<span className="shrink-0 text-foreground-light">Authorizing as</span><span className="flex min-w-0 items-center gap-2"><span className="min-w-0 truncate text-right text-foreground">{email}</span>- <Tooltip>- <TooltipTrigger asChild>- <Button- variant="text"- size="tiny"- icon={<LogOut size={14} />}- className="shrink-0 size-6 px-0 text-foreground-light hover:text-foreground"- aria-label="Sign out"- aria-describedby={undefined}- // Tooltip repeats the label; screen readers would read it twice- onClick={onSignOut}- />- </TooltipTrigger>- <TooltipContent side="top">Sign out</TooltipContent>- </Tooltip>+ <ButtonTooltip+ variant="text"+ size="tiny"+ icon={<LogOut size={14} />}+ className="shrink-0 size-6 px-0 text-foreground-light hover:text-foreground"+ aria-label="Sign out"+ aria-describedby={undefined}+ onClick={onSignOut}+ tooltip={{ content: { side: 'bottom', text: 'Sign out' } }}+ /></span></div><div className="flex items-center justify-between gap-4 py-2.5 text-xs">diff --git a/apps/studio/components/interfaces/Organization/OAuthApps/Consent/OAuthAppsAuthorizeScreen.test.tsx b/apps/studio/components/interfaces/Organization/OAuthApps/Consent/OAuthAppsAuthorizeScreen.test.tsxindex 21c0d487837..449f85ec0cc 100644--- a/apps/studio/components/interfaces/Organization/OAuthApps/Consent/OAuthAppsAuthorizeScreen.test.tsx+++ b/apps/studio/components/interfaces/Organization/OAuthApps/Consent/OAuthAppsAuthorizeScreen.test.tsx@@ -128,8 +128,8 @@ describe('OAuthAppsAuthorizeScreen', () => {expect(screen.getByText('Permissions granted')).toBeInTheDocument()expect(screen.queryByText('Permissions requested')).not.toBeInTheDocument()- expect(screen.getByText('Database, Environment, Secrets')).toBeInTheDocument()- expect(screen.getByText('Projects, Edge Functions, Storage')).toBeInTheDocument()+ expect(screen.getByText('Database, Environment, Analytics')).toBeInTheDocument()+ expect(screen.getByText('Secrets, Projects, Edge Functions, Storage')).toBeInTheDocument()})test('an organization-bound app reaches the success screen with the authorizing identity', async () => {@@ -358,4 +358,43 @@ describe('OAuthAppsAuthorizeScreen', () => {expect(await screen.findByText('tailspin-shop')).toBeInTheDocument()expect(screen.getByRole('combobox')).not.toHaveTextContent('tailspin-warehouse')})++ test('reconsent shows the permissions differences', async () => {+ renderScreen({+ authId: OAUTH_APPS_MOCK_SCENARIOS.vercelReconsent,+ })++ await screen.findByText('Already granted (2)')+ await screen.findByText((_, element) => element?.textContent == 'Environment (New)', {+ selector: 'span',+ })+ await screen.findByText(+ (_, element) => element?.textContent == 'Analytics (Upgraded from Read)',+ { selector: 'span' }+ )+ await screen.findByText(+ (_, element) => element?.textContent == 'Secrets (Demoted from Read-write)',+ { selector: 'span' }+ )+ await screen.findByText((_, element) => element?.textContent == 'Edge Functions (New)', {+ selector: 'span',+ })+ await screen.findByText((_, element) => element?.textContent == 'Storage (New)', {+ selector: 'span',+ })+ await screen.findByText((_, element) => element?.textContent == 'Rest (Read)', {+ selector: 'span',+ })+ })++ test('reconsent shows the previous permissions hidden by default', async () => {+ renderScreen({+ authId: OAUTH_APPS_MOCK_SCENARIOS.vercelReconsent,+ })++ await screen.findByText('Already granted (2)')+ expect(screen.queryByText('Database')).toBeNull()+ fireEvent.click(await screen.findByText('Already granted (2)'))+ await screen.findByText('Database')+ })})diff --git a/apps/studio/components/interfaces/Organization/OAuthApps/Consent/OAuthAppsAuthorizeScreen.tsx b/apps/studio/components/interfaces/Organization/OAuthApps/Consent/OAuthAppsAuthorizeScreen.tsxindex cfa9a3be963..3cc13f2266e 100644--- a/apps/studio/components/interfaces/Organization/OAuthApps/Consent/OAuthAppsAuthorizeScreen.tsx+++ b/apps/studio/components/interfaces/Organization/OAuthApps/Consent/OAuthAppsAuthorizeScreen.tsx@@ -1,6 +1,7 @@import { useEffect, useRef, useState } from 'react'import { Button } from 'ui'import { Admonition } from 'ui-patterns/Admonition'+import { TimestampInfo } from 'ui-patterns/TimestampInfo'import { AuthorizeSuccessScreen } from './AuthorizeSuccessScreen'import { AuthorizingAsCard } from './AuthorizingAsCard'@@ -8,6 +9,7 @@ import { NoProjectsNotice } from './NoProjectsNotice'import { CONSENT_COPY } from './OAuthAppsAuthorizeScreen.utils'import { MAX_SELECTED_PROJECTS, ProjectMultiSelect } from './ProjectMultiSelect'import { ScopeGroupCard } from './ScopeGroupCard'+import { ScopeGroupCardWithDiff } from './ScopeGroupCardWithDiff'import { useMemberOrganization } from './useMemberOrganization'import {DestinationLogo,@@ -50,6 +52,8 @@ export const OAuthAppsAuthorizeScreen = ({projectRef = null,navigate,}: OAuthAppsAuthorizeScreenProps) => {+ const signOut = useSignOut()+const grantKind = request.grant_kindconst isProjectScopingModeEnabled = request.project_scoping_mode@@ -60,41 +64,57 @@ export const OAuthAppsAuthorizeScreen = ({null)- const identityQuery = useOAuthAppsAuthorizeOrganizationsQuery({ id: authId })- const memberOrgQuery = useMemberOrganization({+ const {+ data: identity,+ error: identityError,+ isPending: isPendingIdentity,+ isError: isErrorIdentity,+ } = useOAuthAppsAuthorizeOrganizationsQuery({ id: authId })++ const {+ data: memberOrg,+ error: memberOrgError,+ isPending: isPendingMemberOrg,+ isError: isErrorMemberOrg,+ } = useMemberOrganization({authId,organizationSlug,projectRef,request,})- const projectsQuery = useOAuthAppsAuthorizeOrganizationProjectsQuery(+ const { data: projects } = useOAuthAppsAuthorizeOrganizationProjectsQuery({id: authId,- slug: memberOrgQuery.data || '',+ slug: memberOrg || '',},{- enabled: !memberOrgQuery.isPending && !!memberOrgQuery.data,+ enabled: !isPendingMemberOrg && !!memberOrg,})- const appDetailsQuery = useOAuthOrgAppDetailsQuery(++ const {+ data: appDetails,+ isPending: isPendingAppDetails,+ isError: isErrorAppDetails,+ error: errorAppDetails,+ } = useOAuthOrgAppDetailsQuery({- slug: memberOrgQuery.data || '',+ slug: memberOrg || '',appId: request.app_id,},{- enabled: !memberOrgQuery.isPending && !!memberOrgQuery.data,+ enabled: !isPendingMemberOrg && !!memberOrg,})const seeded = useRef(false)useEffect(() => {- if (seeded.current || !projectsQuery.data || !appDetailsQuery.data || !memberOrgQuery.data)- return+ if (seeded.current || !projects || !appDetails || !memberOrg) returnseeded.current = trueif (!isProjectScopingModeEnabled) return- const grant = appDetailsQuery.data.existing_grant+ const grant = appDetails.existing_grantconst hasAllProjectsGrant = grant !== null && grant.project_refs.length === 0if (hasAllProjectsGrant && isProjectScopingModeEnabled) {setAllProjectsSelected(true)@@ -104,26 +124,18 @@ export const OAuthAppsAuthorizeScreen = ({const refs = getPreselectedProjectRefs({existingGrant: grant,projectRef,- liveProjects: projectsQuery.data,+ liveProjects: projects,})if (refs.length > 0) setSelectedProjectRefs(refs.slice(0, MAX_SELECTED_PROJECTS))- }, [- appDetailsQuery.data,- projectsQuery.data,- memberOrgQuery.data,- isProjectScopingModeEnabled,- projectRef,- ])-- const signOut = useSignOut()+ }, [appDetails, projects, memberOrg, isProjectScopingModeEnabled, projectRef])const preflightQuery = useOAuthAppsPreflightValidationQuery({appId: request.app_id,- slug: memberOrgQuery.data!,+ slug: memberOrg!,},{- enabled: !memberOrgQuery.isPending && !!memberOrgQuery.data,+ enabled: !isPendingMemberOrg && !!memberOrg,})@@ -144,12 +156,12 @@ export const OAuthAppsAuthorizeScreen = ({})const isSubmitting = approveMutation.isPending- const hasProjects = (projectsQuery.data?.length ?? 0) > 0+ const hasProjects = (projects?.length ?? 0) > 0const isBlockedOnProjects = isProjectScopingModeEnabled && !hasProjectsconst canProceed = !isBlockedOnProjects- const grantedProjects = (projectsQuery.data ?? []).filter((project) =>+ const grantedProjects = (projects ?? []).filter((project) =>selectedProjectRefs.includes(project.ref))@@ -165,11 +177,11 @@ export const OAuthAppsAuthorizeScreen = ({const usesSelectedProjects = isProjectScopingModeEnabled && !allProjectsSelectedconst hasNoSelection = usesSelectedProjects && selectedProjectRefs.length === 0- if (identityQuery.isPending || memberOrgQuery.isPending) {+ if (isPendingIdentity || isPendingMemberOrg) {return null}- if (identityQuery.isError) {+ if (isErrorIdentity) {return (<InterstitialLayoutlogo={<DestinationLogo name={request.name} />}@@ -177,16 +189,27 @@ export const OAuthAppsAuthorizeScreen = ({description="This application wants to access your Supabase Account"><div className="flex flex-col gap-6 px-6 pb-6">- <AlertError- subject="An error occurred while loading your data"- error={identityQuery.error}- />+ <AlertError subject="An error occurred while loading your data" error={identityError} /></div></InterstitialLayout>)}- if (memberOrgQuery.isError) {+ if (isErrorAppDetails) {+ return (+ <InterstitialLayout+ logo={<DestinationLogo name={request.name} />}+ title={`Authorize ${request.name}`}+ description="This application wants to access your Supabase Account"+ >+ <div className="flex flex-col gap-6 px-6 pb-6">+ <AlertError subject="An error occurred while loading your data" error={errorAppDetails} />+ </div>+ </InterstitialLayout>+ )+ }++ if (isErrorMemberOrg) {return (<InterstitialLayoutlogo={<DestinationLogo name={request.name} />}@@ -195,8 +218,8 @@ export const OAuthAppsAuthorizeScreen = ({><div className="flex flex-col gap-6 px-6 pb-6"><AlertError+ error={memberOrgError}subject="We couldn't find the organization for this application authorization"- error={memberOrgQuery.error}/></div></InterstitialLayout>@@ -214,8 +237,8 @@ export const OAuthAppsAuthorizeScreen = ({<AuthorizeSuccessScreenappName={request.name}grant={{- email: identityQuery.data.email,- organization_slug: memberOrgQuery.data,+ email: identity.email,+ organization_slug: memberOrg,project_refs: usesSelectedProjects ? selectedProjectRefs : null,projects: grantedProjects,scopes: request.scopes,@@ -243,11 +266,11 @@ export const OAuthAppsAuthorizeScreen = ({const approveBody: OAuthAuthorizeApproveRequest = usesSelectedProjects? { project_refs: selectedProjectRefs }: {}- approveMutation.mutate({ auth_id: authId, slug: memberOrgQuery.data, body: approveBody })+ approveMutation.mutate({ auth_id: authId, slug: memberOrg, body: approveBody })}const handleDeny = () => {- denyMutation.mutate({ auth_id: authId, slug: memberOrgQuery.data })+ denyMutation.mutate({ auth_id: authId, slug: memberOrg })}const footerMessage = isSubmitting@@ -262,14 +285,28 @@ export const OAuthAppsAuthorizeScreen = ({<InterstitialLayoutlogo={<LogoPair left={<DestinationLogo name={request.name} />} right={<SupabaseLogo />} />}title={`Authorize ${request.name}`}- description="This application wants to access your Supabase Account"+ description={+ appDetails?.existing_grant ? (+ <>+ You authorized {request.name} for this organization on{' '}+ <TimestampInfo+ className="text-sm inline-block"+ utcTimestamp={appDetails.existing_grant.approved_at}+ labelFormat="D MMM YYYY"+ />+ . It's now asking for different access.+ </>+ ) : (+ 'This application wants to access your Supabase Account'+ )+ }><div className="flex flex-col gap-6 px-6 pb-6">{preflightQuery.data?.status === 'error' && (<Admonitiontype="warning"title={CONSENT_COPY.roleFailureAllProjects.title(request.name)}- description={CONSENT_COPY.roleFailureAllProjects.description(memberOrgQuery.data)}+ description={CONSENT_COPY.roleFailureAllProjects.description(memberOrg)}/>)}{hasRoleFailure && (@@ -282,8 +319,8 @@ export const OAuthAppsAuthorizeScreen = ({<fieldset disabled={isSubmitting} className="contents"><AuthorizingAsCard- email={identityQuery.data.email}- organizationSlug={memberOrgQuery.data}+ email={identity.email}+ organizationSlug={memberOrg}onSignOut={handleSignOut}request={request}/>@@ -291,7 +328,7 @@ export const OAuthAppsAuthorizeScreen = ({{isBlockedOnProjects && (<NoProjectsNoticeappName={request.name}- organizationSlug={memberOrgQuery.data}+ organizationSlug={memberOrg}onSwitchOrg={handleSwitchOrg}/>)}@@ -299,7 +336,7 @@ export const OAuthAppsAuthorizeScreen = ({{canProceed && isProjectScopingModeEnabled && (<div className="flex flex-col gap-2"><ProjectMultiSelect- projects={projectsQuery.data ?? []}+ projects={projects ?? []}selectedRefs={selectedProjectRefs}onChange={setSelectedProjectRefs}maxSelected={MAX_SELECTED_PROJECTS}@@ -316,7 +353,14 @@ export const OAuthAppsAuthorizeScreen = ({<><section className="flex flex-col gap-3"><p className="text-sm text-foreground">Permissions requested</p>- <ScopeGroupCard scopes={request.scopes} />+ {appDetails?.existing_grant?.approved_scopes ? (+ <ScopeGroupCardWithDiff+ scopes={request.scopes}+ previousScopes={appDetails.existing_grant.approved_scopes}+ />+ ) : (+ <ScopeGroupCard scopes={request.scopes} />+ )}<p className="text-xs text-foreground-lighter">Authorizing {request.name} grants it access to the permissions{isProjectScopingModeEnabled && !allProjectsSelected@@ -342,7 +386,7 @@ export const OAuthAppsAuthorizeScreen = ({<Buttonblockvariant={primaryActionVariant}- loading={isSubmitting}+ loading={isSubmitting || isPendingAppDetails}disabled={cannotApprove}aria-label={primaryActionLabel}onClick={hasRoleFailure ? handleDeselectFlagged : handleApprove}diff --git a/apps/studio/components/interfaces/Organization/OAuthApps/Consent/OAuthAppsAuthorizeScreen.utils.test.ts b/apps/studio/components/interfaces/Organization/OAuthApps/Consent/OAuthAppsAuthorizeScreen.utils.test.tsindex 2877d64e512..e93cb683324 100644--- a/apps/studio/components/interfaces/Organization/OAuthApps/Consent/OAuthAppsAuthorizeScreen.utils.test.ts+++ b/apps/studio/components/interfaces/Organization/OAuthApps/Consent/OAuthAppsAuthorizeScreen.utils.test.ts@@ -1,8 +1,59 @@import { describe, expect, test } from 'vitest'-import { formatPermissionName, groupScopesByLevel } from './OAuthAppsAuthorizeScreen.utils'+import {+ formatPermissionName,+ getDiffBetweenScopes,+ groupScopesByLevel,+} from './OAuthAppsAuthorizeScreen.utils'describe('OAuthAppsAuthorizeScreen', () => {+ describe('getDiffBetweenScopes', () => {+ test('returns the proper differences between two set of scopes', () => {+ expect(+ getDiffBetweenScopes({+ scopes: [+ // Upgraded to read-write+ 'analytics:read',+ 'analytics:write',+ // Changed to write only+ 'analytics_config:write',+ // Changed to read only+ 'auth:read',+ // Unchanged read-write+ 'database:read',+ 'database:write',+ // Unchanged write+ 'domains:write',+ // Unchanged read+ 'edge_functions:read',+ ],+ previousScopes: [+ 'analytics:read',+ 'analytics_config:read',+ 'auth:write',+ 'database:read',+ 'database:write',+ 'domains:write',+ 'edge_functions:read',+ // Removed+ 'secrets:read',+ ],+ })+ ).toEqual({+ unchanged: {+ 'read-write': ['database'],+ write: ['domains'],+ read: ['edge_functions'],+ },+ changed: {+ 'read-write': [{ permission: 'analytics', previousLevel: 'read' }],+ write: [{ permission: 'analytics_config', previousLevel: 'read' }],+ read: [{ permission: 'auth', previousLevel: 'write' }],+ removed: [{ permission: 'secrets', previousLevel: 'read' }],+ },+ })+ })+ })describe('groupScopesByLevel', () => {test('groups scopes by level', () => {expect(@@ -12,34 +63,19 @@ describe('OAuthAppsAuthorizeScreen', () => {'projects:write','analytics_config:write',])- ).toEqual([- {- level: 'read-write',- permissions: ['projects'],- },- {- level: 'write',- permissions: ['analytics_config'],- },- {- level: 'read',- permissions: ['organizations'],- },- ])+ ).toEqual({+ ['read-write']: ['projects'],+ write: ['analytics_config'],+ read: ['organizations'],+ })})test('excludes empty groups', () => {expect(groupScopesByLevel(['projects:read', 'organizations:read', 'projects:write'])).toEqual(- [- {- level: 'read-write',- permissions: ['projects'],- },- // No write group- {- level: 'read',- permissions: ['organizations'],- },- ]+ {+ 'read-write': ['projects'],+ write: [],+ read: ['organizations'],+ })})})diff --git a/apps/studio/components/interfaces/Organization/OAuthApps/Consent/OAuthAppsAuthorizeScreen.utils.ts b/apps/studio/components/interfaces/Organization/OAuthApps/Consent/OAuthAppsAuthorizeScreen.utils.tsindex 7ecd511846c..bd413be1d3b 100644--- a/apps/studio/components/interfaces/Organization/OAuthApps/Consent/OAuthAppsAuthorizeScreen.utils.ts+++ b/apps/studio/components/interfaces/Organization/OAuthApps/Consent/OAuthAppsAuthorizeScreen.utils.ts@@ -58,32 +58,11 @@ export function groupScopesByLevel(scopes: OAuthScope[]) {}}- return [- ...(readWrite.size > 0- ? [- {- level: 'read-write' as const,- permissions: Array.from(readWrite),- },- ]- : []),- ...(write.size > 0- ? [- {- level: 'write' as const,- permissions: Array.from(write),- },- ]- : []),- ...(read.size > 0- ? [- {- level: 'read' as const,- permissions: Array.from(read),- },- ]- : []),- ]+ return {+ ['read-write']: Array.from(readWrite),+ ['write']: Array.from(write),+ ['read']: Array.from(read),+ }}export function formatPermissionName(name: string) {@@ -93,8 +72,106 @@ export function formatPermissionName(name: string) {.join(' ')}-export function getScopeLevelLabel(level: 'read' | 'write' | 'read-write') {- if (level === 'read') return 'READ'- if (level === 'write') return 'WRITE'- return 'READ-WRITE'+export type ScopeGroupLevel = 'read' | 'write' | 'read-write'++type ScopeGroup = {+ 'read-write': string[]+ write: string[]+ read: string[]+}++export type DiffScopePermission = {+ permission: string+ previousLevel: ScopeGroupLevel | undefined+}++type DiffScopeGroup = {+ 'read-write': DiffScopePermission[]+ write: DiffScopePermission[]+ read: DiffScopePermission[]+ removed: DiffScopePermission[]+}++type ScopePermission = OAuthScope extends `${infer Permission}:${string}` ? Permission : never+type ScopeLevel = OAuthScope extends `${string}:${infer Level}` ? Level : never++export const getDiffBetweenScopes = ({+ scopes,+ previousScopes,+}: {+ scopes: OAuthScope[]+ previousScopes: OAuthScope[]+}) => {+ const unchanged: ScopeGroup = { 'read-write': [], write: [], read: [] }+ const changed: DiffScopeGroup = { 'read-write': [], write: [], read: [], removed: [] }++ const permissionsWithLevel = getPermissionsWithLevel(scopes)+ const previousPermissionsWithLevel = getPermissionsWithLevel(previousScopes)++ const permissionsKeys = Object.keys(permissionsWithLevel) as ScopePermission[]+ for (const permission of permissionsKeys) {+ // New permission+ if (!previousPermissionsWithLevel[permission]) {+ changed[permissionsWithLevel[permission]!].push({ permission, previousLevel: undefined })+ continue+ }++ // Updated permission+ if (permissionsWithLevel[permission] !== previousPermissionsWithLevel[permission]) {+ changed[permissionsWithLevel[permission]!].push({+ permission,+ previousLevel: previousPermissionsWithLevel[permission],+ })+ continue+ }++ // Unchanged permission+ unchanged[permissionsWithLevel[permission]].push(permission)+ }++ // Now detect removed permissions+ const previousPermissionsKeys = Object.keys(previousPermissionsWithLevel) as ScopePermission[]+ for (const permission of previousPermissionsKeys) {+ if (permissionsWithLevel[permission] == null) {+ changed.removed.push({+ permission,+ previousLevel: previousPermissionsWithLevel[permission],+ })+ }+ }++ return { unchanged, changed }+}++export const getPermissionsWithLevel = (scopes: OAuthScope[]) => {+ const scopesWithLevel: Partial<Record<ScopePermission, ScopeGroupLevel>> = {}++ for (const scope of scopes) {+ const [permission, level] = extractPermissionAndLevelFromScope(scope)++ if (!scopesWithLevel[permission]) {+ scopesWithLevel[permission] = level+ }+ if (scopesWithLevel[permission] === 'read-write') {+ continue+ }+ if (scopesWithLevel[permission] === 'read' && level === 'write') {+ scopesWithLevel[permission] = 'read-write'+ continue+ }++ if (scopesWithLevel[permission] === 'write' && level === 'read') {+ scopesWithLevel[permission] = 'read-write'+ continue+ }+ }++ return scopesWithLevel+}++export const extractPermissionAndLevelFromScope = (+ scope: OAuthScope+): [ScopePermission, ScopeLevel] => {+ const [permission, level] = scope.split(':')+ return [permission as ScopePermission, level as ScopeLevel]}diff --git a/apps/studio/components/interfaces/Organization/OAuthApps/Consent/ScopeGroupCard.tsx b/apps/studio/components/interfaces/Organization/OAuthApps/Consent/ScopeGroupCard.tsxindex 6eef35ee76e..f9c1b23792b 100644--- a/apps/studio/components/interfaces/Organization/OAuthApps/Consent/ScopeGroupCard.tsx+++ b/apps/studio/components/interfaces/Organization/OAuthApps/Consent/ScopeGroupCard.tsx@@ -1,39 +1,21 @@import { useMemo } from 'react'-import {- formatPermissionName,- getScopeLevelLabel,- groupScopesByLevel,-} from './OAuthAppsAuthorizeScreen.utils'+import { groupScopesByLevel } from './OAuthAppsAuthorizeScreen.utils'+import { ScopeGroupCardItem } from './ScopeGroupCardItem'import type { OAuthScope } from '@/data/oauth-apps/types'export interface ScopeGroupCardProps {scopes: OAuthScope[]}-type ScopeGroupLevel = 'read' | 'write' | 'read-write'-type ScopeGroup = {- level: ScopeGroupLevel- permissions: string[]-}-export const ScopeGroupCard = ({ scopes }: ScopeGroupCardProps) => {- const scopeGroups = useMemo<ScopeGroup[]>(() => groupScopesByLevel(scopes), [scopes])+ const scopeGroups = useMemo(() => groupScopesByLevel(scopes), [scopes])return (<div className="divide-y rounded-md border bg-surface-75 px-4">- {scopeGroups.map((scopeGroup) => (- <div key={scopeGroup.level} className="flex flex-col gap-2 py-3">- <p className="font-mono text-[11px] uppercase tracking-wider text-foreground-light">- {getScopeLevelLabel(scopeGroup.level)}- </p>- <p className="text-xs font-medium text-foreground">- {scopeGroup.permissions- .map((permission) => formatPermissionName(permission))- .join(', ')}- </p>- </div>- ))}+ <ScopeGroupCardItem label="READ-WRITE" permissions={scopeGroups['read-write']} />+ <ScopeGroupCardItem label="WRITE" permissions={scopeGroups['write']} />+ <ScopeGroupCardItem label="READ" permissions={scopeGroups['read']} /></div>)}diff --git a/apps/studio/components/interfaces/Organization/OAuthApps/Consent/ScopeGroupCardItem.tsx b/apps/studio/components/interfaces/Organization/OAuthApps/Consent/ScopeGroupCardItem.tsxnew file mode 100644index 00000000000..9981f59c601--- /dev/null+++ b/apps/studio/components/interfaces/Organization/OAuthApps/Consent/ScopeGroupCardItem.tsx@@ -0,0 +1,21 @@+import { type ReactNode } from 'react'++import { formatPermissionName } from './OAuthAppsAuthorizeScreen.utils'++export const ScopeGroupCardItem = ({+ label,+ permissions,+}: {+ label: ReactNode+ permissions: string[]+}) => {+ if (permissions.length === 0) return null+ return (+ <div className="flex flex-col gap-2 py-3">+ <p className="font-mono text-xs uppercase text-foreground-light">{label}</p>+ <p className="text-xs font-medium text-foreground">+ {permissions.map((permission) => formatPermissionName(permission)).join(', ')}+ </p>+ </div>+ )+}diff --git a/apps/studio/components/interfaces/Organization/OAuthApps/Consent/ScopeGroupCardWithDiff.tsx b/apps/studio/components/interfaces/Organization/OAuthApps/Consent/ScopeGroupCardWithDiff.tsxnew file mode 100644index 00000000000..8ed7b812d65--- /dev/null+++ b/apps/studio/components/interfaces/Organization/OAuthApps/Consent/ScopeGroupCardWithDiff.tsx@@ -0,0 +1,123 @@+import { capitalize } from 'lodash'+import { ChevronsUpDownIcon } from 'lucide-react'+import { Fragment, useMemo, type ReactNode } from 'react'+import { Button, Collapsible, CollapsibleContent, CollapsibleTrigger } from 'ui'++import {+ DiffScopePermission,+ formatPermissionName,+ getDiffBetweenScopes,+ ScopeGroupLevel,+} from './OAuthAppsAuthorizeScreen.utils'+import { ScopeGroupCardItem } from './ScopeGroupCardItem'+import type { OAuthScope } from '@/data/oauth-apps/types'++export interface ScopeGroupCardProps {+ scopes: OAuthScope[]+ previousScopes: OAuthScope[]+}++export const ScopeGroupCardWithDiff = ({ scopes, previousScopes }: ScopeGroupCardProps) => {+ const diff = useMemo(+ () => getDiffBetweenScopes({ scopes, previousScopes }),+ [scopes, previousScopes]+ )++ const unchangedPermissionsCount =+ diff.unchanged['read-write'].length ++ diff.unchanged['write'].length ++ diff.unchanged['read'].length++ return (+ <>+ <div className="divide-y rounded-md border bg-surface-75 px-4">+ <DiffScopeGroupItem+ label="READ-WRITE"+ level="read-write"+ permissions={diff.changed['read-write']}+ />+ <DiffScopeGroupItem label="WRITE" level="write" permissions={diff.changed['write']} />+ <DiffScopeGroupItem label="READ" level="read" permissions={diff.changed['read']} />+ <DiffScopeGroupItem+ label="REMOVED"+ level={undefined}+ permissions={diff.changed['removed']}+ />+ </div>+ <Collapsible className="flex flex-col gap-2">+ <CollapsibleTrigger asChild>+ <Button+ block+ iconRight={<ChevronsUpDownIcon className="h-4 w-4" />}+ variant="text"+ size="tiny"+ className="p-0 flex justify-center text-foreground-lighter"+ >+ <span>Already granted ({unchangedPermissionsCount})</span>+ </Button>+ </CollapsibleTrigger>+ <CollapsibleContent>+ <div className="divide-y rounded-md border bg-surface-75 px-4">+ <ScopeGroupCardItem label="READ-WRITE" permissions={diff.unchanged['read-write']} />+ <ScopeGroupCardItem label="WRITE" permissions={diff.unchanged['write']} />+ <ScopeGroupCardItem label="READ" permissions={diff.unchanged['read']} />+ </div>+ </CollapsibleContent>+ </Collapsible>+ </>+ )+}++const DiffScopeGroupItem = ({+ label,+ level,+ permissions,+}: {+ label: ReactNode+ level: ScopeGroupLevel | undefined+ permissions: DiffScopePermission[]+}) => {+ if (permissions.length === 0) return null+ return (+ <div className="flex flex-col gap-2 py-3">+ <p className="font-mono text-xs uppercase text-foreground-light">{label}</p>+ <p className="text-xs font-medium text-foreground">+ {permissions.map((permission, index) => (+ <Fragment key={permission.permission}>+ <span className="inline-block">+ {formatPermissionName(permission.permission)}{' '}+ <span className="text-foreground-lighter">+ (<DiffDescription level={level} previousLevel={permission.previousLevel} />)+ </span>+ </span>+ {index < permissions.length - 1 && <span className="text-foreground-lighter">, </span>}+ </Fragment>+ ))}+ </p>+ </div>+ )+}++const DiffDescription = ({+ level,+ previousLevel,+}: {+ level: ScopeGroupLevel | undefined+ previousLevel: ScopeGroupLevel | undefined+}) => {+ // Removed+ if (level == null) return capitalize(previousLevel!)++ // New+ if (previousLevel == null) return 'New'++ // Upgraded+ if (level === 'read-write') return `Upgraded from ${capitalize(previousLevel)}`++ // Modified+ if (['read', 'write'].includes(level!) && ['read', 'write'].includes(previousLevel))+ return `Changed from ${capitalize(previousLevel)}`++ // Downgraded+ return `Demoted from ${capitalize(previousLevel)}`+}diff --git a/apps/studio/data/oauth-apps/mocks.ts b/apps/studio/data/oauth-apps/mocks.tsindex 73164f9a56d..8cb0be51f39 100644--- a/apps/studio/data/oauth-apps/mocks.ts+++ b/apps/studio/data/oauth-apps/mocks.ts@@ -73,10 +73,11 @@ const VERCEL_SCOPES: OAuthScope[] = ['environment:read','environment:write','secrets:read',- 'secrets:write','projects:read','edge_functions:read','storage:read',+ 'analytics:read',+ 'analytics:write',]const VERCEL_REQUEST: OAuthAppsAuthorizeRequest = {@@ -279,7 +280,15 @@ const MOCK_ORGANIZATION_PROJECTS: Record<string, OAuthAppsAuthorizeOrganizationP}const TAILSPIN_VERCEL_EXISTING_GRANT: OAuthExistingGrant = {- approved_scopes: ['database:read', 'database:write', 'projects:read'],+ approved_scopes: [+ 'database:read',+ 'database:write',+ 'analytics:read',+ 'projects:read',+ 'secrets:read',+ 'secrets:write',+ 'rest:read',+ ],project_refs: ['tailspinshop1', 'tailspindeleted1'],approved_at: '2026-08-14T09:12:00.000Z',}