mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
## Problem The grants dialog makes project coverage and each member’s permissions hard to inspect. ## Solution - Replace the dialog with a grant-details sheet. - Separate organisation and member access, with project references and permissions grouped by access level. - Move app IDs into Details and add a revoke action for authorised admins. - Build on #54285 using the existing grants API. | Before | After | | --- | --- | | <img width="1280" height="1323" alt="OAuth Apps Organization Settings Basket Supabase" src="https://github.com/user-attachments/assets/b6bb0082-9cee-48b4-adb4-058f14f10f9f" /> | <img width="1280" height="1323" alt="OAuth Apps Organization Settings Basket Supabase" src="https://github.com/user-attachments/assets/b32a7723-9fa0-452d-95f5-1762fd364163" /> | | <img width="1280" height="1185" alt="OAuth Apps Organization Settings Basket Supabase" src="https://github.com/user-attachments/assets/9a7982ba-aebe-42f4-9ac6-9308136150f7" /> | <img width="1280" height="1221" alt="OAuth Apps Organization Settings Basket Supabase" src="https://github.com/user-attachments/assets/1965f7e4-8554-4fa9-86ef-7e53af1d0038" /> | ## Review instructions 1. Sign in to staging and use an authorised app, or [authorise the test app](https://api.supabase.green/v1/oauth/authorize?client_id=75e64165-b74e-432f-bb70-80d6ae432f06&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A54321%2Fcallback&state=grant-sheet-review). The localhost callback may fail after the grant is saved. 2. Open the [preview](https://studio-staging-git-dnywh-oauth-grant-details-supabase.vercel.app/dashboard/org/_/apps#authorized-apps), select the same organisation and choose **Manage app → View access**. 3. Check the grant sections, project references and permission groups. Test narrow widths, closing the sheet and cancelling **Revoke access**. ### Mixed-grant overrides In **DevTools → Network**, override only the GET ending in `/oauth/approvals/<app-id>/grants` with this response. Save, reload and reopen the sheet. Remove any parent `/approvals` override to avoid Chrome’s file/folder clash. <details> <summary>grants.json</summary> ```json { "data": [ { "id": "22222222-2222-4222-8222-000000000001", "type": "oauth_grant", "attributes": { "approved_at": "2026-11-30T00:00:00Z", "approved_scopes": [ "database:read", "database:write", "projects:read" ], "kind": "organization_bound", "projects": null, "user": null } }, { "id": "22222222-2222-4222-8222-000000000002", "type": "oauth_grant", "attributes": { "approved_at": "2026-11-30T00:00:00Z", "approved_scopes": [ "projects:read" ], "kind": "member_bound", "projects": [ { "name": "Example storefront", "ref": "example-storefront" } ], "user": { "username": "alex", "email": "alex@example.com", "gotrue_id": "33333333-3333-4333-8333-000000000001" } } }, { "id": "22222222-2222-4222-8222-000000000003", "type": "oauth_grant", "attributes": { "approved_at": "2026-11-30T00:00:00Z", "approved_scopes": [], "kind": "member_bound", "projects": [], "user": { "username": "sam", "email": "sam@example.com", "gotrue_id": "33333333-3333-4333-8333-000000000002" } } } ], "links": { "next": null, "prev": null } } ``` </details> Check that organisation access covers all projects, Alex has only read access to Example storefront, and Sam has no projects or permissions. Disable overrides when finished. Requires `enableScopedOAuthManage` for the organisation.
143 lines
5.0 KiB
TypeScript
143 lines
5.0 KiB
TypeScript
import { useIntersectionObserver } from '@uidotdev/usehooks'
|
|
import { useParams } from 'common'
|
|
import { BuildingIcon, UserIcon } from 'lucide-react'
|
|
import { ComponentProps, useEffect, useRef } from 'react'
|
|
import { Button, SheetContent, SheetFooter, SheetHeader, SheetSection, SheetTitle } from 'ui'
|
|
import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
|
|
|
|
import { IdCopyChip } from './IdCopyChip'
|
|
import { OAuthGrantAccess } from './OAuthGrantAccess'
|
|
import { OAuthGrantAccordion } from './OAuthGrantAccordionItem'
|
|
import { AlertError } from '@/components/ui/AlertError'
|
|
import { OAuthApproval } from '@/data/oauth-apps/oauth-apps-approvals-query'
|
|
import { useOAuthAppMemberGrantsQuery } from '@/data/oauth-apps/oauth-apps-member-grants-query'
|
|
|
|
interface OAuthAppsGrantDetailsSheetProps extends ComponentProps<typeof SheetContent> {
|
|
approval: OAuthApproval
|
|
onRevoke?: () => void
|
|
}
|
|
|
|
export const OAuthAppsGrantDetailsSheet = ({
|
|
approval,
|
|
onRevoke,
|
|
...props
|
|
}: OAuthAppsGrantDetailsSheetProps) => {
|
|
const titleRef = useRef<HTMLHeadingElement>(null)
|
|
const { slug } = useParams()
|
|
const {
|
|
data,
|
|
error,
|
|
isPending,
|
|
isError,
|
|
isSuccess,
|
|
hasNextPage,
|
|
fetchNextPage,
|
|
isFetchingNextPage,
|
|
} = useOAuthAppMemberGrantsQuery({ slug, appId: approval.id })
|
|
|
|
const [sentinelRef, entry] = useIntersectionObserver({
|
|
root: null,
|
|
threshold: 0,
|
|
rootMargin: '0px',
|
|
})
|
|
|
|
useEffect(() => {
|
|
if (hasNextPage && entry?.isIntersecting && !isFetchingNextPage && !isError) {
|
|
fetchNextPage()
|
|
}
|
|
}, [hasNextPage, entry?.isIntersecting, fetchNextPage, isFetchingNextPage, isError])
|
|
|
|
const grants = data?.pages.flatMap((page) => page.data) ?? []
|
|
const organizationGrants = grants.filter(
|
|
(grant) => grant.attributes.kind === 'organization_bound'
|
|
)
|
|
const memberGrants = grants.filter((grant) => grant.attributes.kind === 'member_bound')
|
|
const isEmpty = grants.length === 0
|
|
let statusText = 'Grants loaded'
|
|
if (isFetchingNextPage) statusText = 'Loading more grants...'
|
|
else if (isPending) statusText = 'Loading grants...'
|
|
else if (isError) statusText = ''
|
|
|
|
return (
|
|
<SheetContent
|
|
size="lg"
|
|
className="flex flex-col gap-0"
|
|
aria-describedby={undefined}
|
|
{...props}
|
|
onOpenAutoFocus={(event) => {
|
|
event.preventDefault()
|
|
titleRef.current?.focus()
|
|
}}
|
|
>
|
|
<SheetHeader className="border-b pr-12 text-left">
|
|
<SheetTitle ref={titleRef} tabIndex={-1} className="outline-none">
|
|
Access for {approval.attributes.app.name}
|
|
</SheetTitle>
|
|
</SheetHeader>
|
|
<SheetSection className="min-h-0 grow overflow-y-auto">
|
|
<h2 className="mb-2 text-base font-medium">Details</h2>
|
|
<dl className="mt-3 mb-8 rounded-md border bg-surface-75 px-4 text-sm">
|
|
<div className="flex flex-wrap items-center justify-between gap-4 py-3">
|
|
<dt className="text-foreground-light">App ID</dt>
|
|
<dd className="min-w-0 break-all">
|
|
<IdCopyChip id={approval.id} label="Copy app ID" />
|
|
</dd>
|
|
</div>
|
|
</dl>
|
|
<p aria-live="polite" className="sr-only">
|
|
{statusText}
|
|
</p>
|
|
{isPending && <ShimmeringLoader />}
|
|
{isError && <AlertError subject="Failed to retrieve grants" error={error} />}
|
|
{isSuccess && isEmpty && (
|
|
<p className="text-sm text-foreground-light">
|
|
No grants have been authorized for this application.
|
|
</p>
|
|
)}
|
|
{organizationGrants.map((grant) => (
|
|
<OAuthGrantAccess
|
|
key={grant.id}
|
|
id={grant.id}
|
|
title="Organization access"
|
|
scopes={grant.attributes.approved_scopes}
|
|
projects={grant.attributes.projects ?? undefined}
|
|
icon={<BuildingIcon size={16} />}
|
|
expanded
|
|
/>
|
|
))}
|
|
{memberGrants.length > 0 && (
|
|
<>
|
|
<h2 className="-mx-5 mb-3 mt-8 border-t px-5 pt-6 text-base font-medium">
|
|
Member access
|
|
</h2>
|
|
<OAuthGrantAccordion defaultValue={[memberGrants[0].id]}>
|
|
{memberGrants.map((grant) => (
|
|
<OAuthGrantAccess
|
|
key={grant.id}
|
|
id={grant.id}
|
|
title={
|
|
grant.attributes.user?.email ?? grant.attributes.user?.username ?? 'Member'
|
|
}
|
|
scopes={grant.attributes.approved_scopes}
|
|
projects={grant.attributes.projects ?? undefined}
|
|
icon={<UserIcon size={16} />}
|
|
/>
|
|
))}
|
|
</OAuthGrantAccordion>
|
|
</>
|
|
)}
|
|
<p ref={sentinelRef} className="text-sm text-foreground-light">
|
|
{isFetchingNextPage ? 'Loading...' : ''}
|
|
</p>
|
|
</SheetSection>
|
|
{onRevoke && (
|
|
<SheetFooter className="border-t">
|
|
<Button variant="danger" onClick={onRevoke}>
|
|
Revoke access
|
|
</Button>
|
|
</SheetFooter>
|
|
)}
|
|
</SheetContent>
|
|
)
|
|
}
|