Skip to content

feat(studio): scoped access token prototype - #47783

Closed
kemaldotearth wants to merge 7 commits into
masterfrom
feat/scoped-pat-updated-ui
Closed

kemaldotearth wants to merge 7 commits into
masterfrom
feat/scoped-pat-updated-ui

Conversation

@kemaldotearth

@kemaldotearth kemaldotearth commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

I have read the CONTRIBUTING.md file.

YES

What kind of change does this PR introduce?

Improvements to scoped access tokens sheet, starting point for new version. Reference PR for @djhi

kemaldotearth and others added 7 commits July 9, 2026 15:15
Introduce the data model for the scoped access-token redesign:
- AccessToken.permissions.ts builds a permission catalog from the real
  FgaPermissions, groups all ~40 resources into five UI categories
  (Project, Database, Application Services, Infrastructure & Delivery,
  Account & Organization), and layers editable risk metadata + copy.
- permission-scope-map.{json,ts}: checked-in cross-reference of scope →
  Management API endpoints + MCP tools, with conjunctive (dual-scope)
  enforcement helpers. Marked TODO to move behind a control-plane endpoint.
- Update access_token_created telemetry + add migration-admonition
  localStorage key.
- Reference: apps/studio/.design/scoped-token-sheet-variant-d.html.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Rebuild scoped token creation as a two-step Sheet matching variant-d:
- Step 1 Configure: token name + expiry Select (7-day default, Recommended
  badge, Custom date picker); resource-access radio cards (Single project /
  Organization) with account-level advanced admonition + confirm checkbox;
  permissions Accordion of the five categories, per-row None/Read/Read-write
  Select and a risk marker with Allows + MCP-tool tooltip.
- Step 2 Review: capability summary grouped by category, computed overall
  risk, real Management API endpoints grouped per capability (dual-scope
  aware) + MCP tool chips, permanence admonition.
- Footer step indicator; one-time token reveal success state.
- Validation surfaces only on attempt (inline resource errors scroll into
  view; Create disabled with zero scopes).
- Rename the scoped create hook to useScopedAccessTokenCreateMutation.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- Merge classic and scoped tokens into a single "Tokens" table via a
  useMergedAccessTokens selector (tags each row classic/scoped, classic
  drives loading/error, scoped failures degrade gracefully). Classic rows
  get a neutral "Classic" badge; row actions route to the correct
  delete/view endpoint by kind. Remove the Classic/Scoped nav tabs.
- Add a dismissible migration admonition (persisted via localStorage) and
  keep classic minting available as a secondary action.
- /account/tokens/scoped now redirects to the merged /account/tokens.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- Move the scope→endpoint/MCP map from a checked-in .json into a TS
  constants module (permission-scope-map.constants.ts) and delete the
  unused apps/studio/.design reference folder.
- Remove the classic-token creation button; scoped generation is now the
  only creation entry point. Reword the migration admonition accordingly.
- Fix the duplicate "Recommended" badge on the expiry trigger (SelectValue
  already mirrors the selected item's badge).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Restore multi-select for the resource-access selectors: the two modes now
pick one or more projects (project_refs[]) or one or more organizations
(organization_slugs[]) via the shared MultiSelector, instead of a single
org+project pair. Updates the form schema (organizationSlugs/projectRefs
arrays), inline validation ("select at least one …"), the review summary,
and the create payload.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@vercel

vercel Bot commented Jul 9, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
studio-self-hosted Ready Ready Preview, Comment Jul 9, 2026 3:00pm
studio-staging Ready Ready Preview, Comment Jul 9, 2026 3:00pm
5 Skipped Deployments
Project Deployment Actions Updated (UTC)
studio Ignored Ignored Jul 9, 2026 3:00pm
design-system Skipped Skipped Jul 9, 2026 3:00pm
docs Skipped Skipped Open in v0 Jul 9, 2026 3:00pm
ui-library Skipped Skipped Jul 9, 2026 3:00pm
zone-www-dot-com Skipped Skipped Open in v0 Jul 9, 2026 3:00pm

Request Review

@supabase

supabase Bot commented Jul 9, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project xguihxuzqibwxjnimxev because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b92ad9f9-8d7e-46e1-9543-b1b69a96a17a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/scoped-pat-updated-ui

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results

passed  234 passed
flaky  4 flaky
skipped  5 skipped

Details

stats  243 tests across 28 suites
duration  7 minutes, 59 seconds
commit  fd97057

Flaky tests

Features › database.spec.ts › Database › Schema Visualizer › table actions work as expected
Features › realtime-inspector.spec.ts › Realtime Inspector › Broadcast Messages › broadcast messages appear in the UI when listening
Features › rls-policies.spec.ts › RLS Policies › Table editor RLS badge › shows Unrestricted badge when RLS is disabled for public table
Features › wrappers.spec.ts › Stripe › can create a stripe wrapper with tables

Skipped tests

Features › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled
Features › sql-editor.spec.ts › SQL Editor › snippet favourite works as expected
Features › sql-editor.spec.ts › SQL Editor › share with team works as expected
Features › sql-editor.spec.ts › SQL Editor › folders works as expected
Features › sql-editor.spec.ts › SQL Editor › other SQL snippets actions work as expected

Comment on lines +42 to +49
return {
tokens,
// Classic drives the primary states; a scoped fetch that is still loading shouldn't block the list.
isLoading: classic.isPending || (scopedEnabled && scoped.isPending),
isError: classic.isError,
error: classic.error,
isSuccess: classic.isSuccess,
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The useMemo above won't help if the hook return value isn't wrapped in a memo too as we are recreating a new object here every time. I would return a useMemo inside which the tokens will be built, but return the hook result object

<p className="text-xs text-foreground-light">{entry.description}</p>
</div>

<Select value={mode} onValueChange={(value) => onChange(value as PermissionMode)}>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a11y: this input has no label

<div className="flex items-center gap-1.5">
<span className="text-sm text-foreground">{category.name}</span>
<Tooltip>
<TooltipTrigger asChild>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a11y: if you set the asChild prop, make sure the child is an interactive element, otherwise keyboard users won't ever see it


return (
<Tooltip>
<TooltipTrigger asChild>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a11y: if you set the asChild prop, make sure the child is an interactive element, otherwise keyboard users won't ever see it

<FormItemLayout name="expiresAt" label="Expires in">
<div className="flex gap-2">
<FormControl className="grow">
<Select value={field.value} onValueChange={handleExpiryChange}>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a11y: no label

</FormControl>

{field.value === 'custom' && (
<DatePicker

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a11y: no label

</p>
</div>

<Input

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a11y: no label

djhi added a commit that referenced this pull request Jul 28, 2026
First stacked PR for scoped PAT extracted from the prototype #47783 to
ease reviewing.
Next stacked PR is #47979

This PR:
- merge the two existing token lists (classic and scoped) into one
- add an admonition about the scoped PAT migration (missing the docs
URL)

## Notes

It's not possible to create classic tokens anymore with the `scopedPAT`
flag enabled.

## How to test

### With the `scopedPAT` enabled (default on staging)

Go to
https://studio-staging-git-scopedpat-merge-token-lists-supabase.vercel.app/dashboard/account/tokens.
- You shouldn't see two tabs anymore
- If you had classic tokens, they should have the _classic_ badge
- You can create scoped tokens
- You have a way to copy newly created tokens above the list upon form
submission

### With the `scopedPAT` disabled (use the devtool to override)
- You shouldn't see two tabs anymore
- If you had classic tokens, they should **not** have the _classic_
badge
- You can create classic tokens
- You have a way to copy newly created tokens above the list upon form
submission

## Screenshots

Before:
<img width="775" height="515" alt="image"
src="https://github.com/user-attachments/assets/35733e7f-6e3e-40f9-ac5b-cfd7caf5d830"
/>

After:
<img width="767" height="671" alt="image"
src="https://github.com/user-attachments/assets/2fd86e6e-6dc6-46c8-9c89-cbfc553e4eb9"
/>
djhi added a commit that referenced this pull request Jul 28, 2026
Second stacked PR for scoped PAT extracted from the prototype #47783 to
ease reviewing.
Previous stacked PR is #47886
Next stacked PR is #48003

This PR:
- refactor the scoped token creation form in a multi-step fashion

## How to test

Go to
https://studio-staging-git-scopedpat-scoped-token-creat-80c55b-supabase.vercel.app/dashboard/account/tokens

- Click the _Generate new token_ button
- Try submitting immediately. It should display errors correctly
- Configure everything except permissions and try submitting. It should
display a warning about missing permissions
- Configure the permissions and submit. It should display the review
step
- Try going back, modify anything and submit

- Create the token. It should display the token value with a button to
copy it and a checkbox to confirm the copy. You cannot close the sheet
at this step until you check the box and click _Done_.
djhi added a commit that referenced this pull request Jul 29, 2026
Third stacked PR for scoped PAT extracted from the prototype #47783 to
ease reviewing.
Previous stacked PR is #47979
Next stacked PR is #47999

This PR add a way to view the tokens permissions

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
  * Added a “View permissions” option for scoped access tokens.
  * Scoped token permissions now open in a dedicated viewing panel.
  * Scoped token support is enabled by default.

* **Bug Fixes**
* Improved token deletion confirmation to clearly identify the selected
token.
  * Deletion dialogs now close correctly after successful removal.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
djhi added a commit that referenced this pull request Jul 29, 2026
Fourth stacked PR for scoped PAT extracted from the prototype #47783 to
ease reviewing.
Previous stacked PR is #48003
Next stacked PR is #48002

This PR:
- fix some accessibility issues
- add unit tests

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Tests**
* Added coverage for creating scoped access tokens at the project,
organization, and account levels.
* Verified validation for required fields, successful token creation,
clipboard copying, and completion flow.

* **Chores**
* Added temporary browser console logging when viewing a scoped access
token.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
djhi added a commit that referenced this pull request Jul 30, 2026
…n API specs (#48182)

Fifth stacked PR for scoped PAT extracted from the prototype #47783 to
ease reviewing.
Previous stacked PR is #47999
Next stacked PR is #48359

This PR refactor how we get the map of which scopes enable which
endpoint or mcp tool. Previously it was an hardcoded file. We now
compute it from the OpenAPI specs of our API. This ensure the map stays
up to date when the API changes.

However, we don't have an always up-to-date equivalent for mcp tools so
we duplicated code from platform that map the OAuth scopes they check
with the FGA permissions.

## Notes

The react-hook-form usage is not great. A follow up PR will fix it

## How to test

- On
https://studio-staging-git-scopedpat-scope-permissions-api-supabase.vercel.app/dashboard/account/tokens
- Create a new token with a few permissions (their risk marker should be
displayed: (_High risk_, _Medium risk_ or _Low risk_)
- You should see the available endpoints and mcp tools in the review
step

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* Added dynamic permission mapping for scoped access tokens, covering
Management API endpoints and MCP tools.
* Added a permissions endpoint with hosted-platform support and caching.
* Updated scoped token creation and review screens to show capabilities
based on granted permissions.
  * Added permission-aware risk indicators and tool visibility.

* **Bug Fixes**
* Improved authorization checks so endpoints and tools require all
necessary scopes.

* **Tests**
  * Added coverage for endpoint, scope, and MCP tool mapping behavior.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@kemaldotearth

Copy link
Copy Markdown
Contributor Author

Closing this as we shipped and this was only ever a prototype.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants