shadcn.io is not affiliated with official shadcn/ui
API Key Builder Settings Block for React
An API key settings panel with a table of keys, a builder that sets None, Read or Write for each resource, and a try-a-request check that answers Allowed or Denied with the reason before anything is saved.
Installation
Overview
Let people shape a key to exactly what it needs, with this API key settings panel for React with Base UI. A hairline frame with a plus mark on each corner starts with a native table of the account's keys: the name with its masked value, a Live or Test Badge, what it can do ("Reads 3, writes 1") and when it last signed a request. Choosing a key loads it into a builder: a name, an environment in a Segment Group and one row per resource (Customers, Charges, Refunds, Payouts, Webhooks), each with a Segment Group of None, Read and Write. Beside the builder, a side cell with its own plus marks holds a request check: pick a method and a resource in two Native Selects and it answers Allowed or Denied with the status code and the reason ("This key has Read on Refunds. A POST needs Write."), worked out from the key as drawn, saved or not, so you see a Read grant refuse a POST before you save. A Copy Button copies the request as a cURL command. The action foot counts unsaved changes in a status line beside a Shine Button that saves the key and an outline Button that discards them; a new key appears in the table, masked. On a phone the table is a list of cards and the check sits under the builder. It's built from Segment Group, Native Select, Field, Input, Badge, Copy Button, Button, Shine Button and Guides, with a CSS entrance only. For a payments or developer API, a dashboard's key page or any product with scoped keys.
FAQ
How do I fill it with my own keys and resources?
Edit the constants at the top. RESOURCES lists what a key can touch, each with a label, a path and a hint. KEYS lists the account's keys, each with its environment, a grant of None, Read or Write per resource, the last day it signed a request and the last four characters of its value: your API should never send back more than that. The "Reads 3, writes 1" summary, the key count and every sentence in the check are worked out from the grants, so nothing is typed twice. Write counts as Read too, so a resource a key can write is also one it can read.
How does the try-a-request check decide?
A GET needs Read; a POST or a DELETE needs Write. The check looks up the grant for the chosen resource in the builder's current draft, not in the saved key, and prints the verdict, a 200 or a 403 and one sentence: no access, Read where Write is needed, or the grant that allows it. It is a small pure function of the grants and nothing is sent. In your app, run the same rule where the key is enforced so the preview can't drift from the real behaviour. The Copy button copies the request as a cURL command that reads the key from an environment variable, so no secret is ever on the page.
What stays local, and how do I wire it up?
Everything. Saving changes the key in this page's state, and a new key is added to the table with a masked value whose last four characters come from a short typed list. No key exists and nothing is stored or sent. To make it real, send the draft to your API in the save handler, add the key it returns to the list, and show its secret once in a dialog (the reveal-once screen is a separate block, dialog-api-key), then keep only the last four characters on this page.
What does Save check, and what happens when I press it?
Save and Discard are always on the page and marked aria-disabled while nothing has changed, so pressing them then says there is nothing to do. A key needs a name and access to at least one resource: if either is missing, Save says so in the status line and an inline message, and moves focus to the name field or the access group. Saving an existing key updates its row and the summary in the table; saving a new one adds a row and selects it. Choosing another key while you have unsaved changes loads it and drops them.
How does it look on a phone, and is it accessible?
Below the medium breakpoint the table becomes one card per key, the builder's fields stack, each resource's three choices fill the row, and the check sits under the builder with the foot pinned to the bottom of the screen. The table is native, with a caption, column headers, and the key's name as a real button that marks the chosen key with aria-current. Every Segment Group is named for its resource ("Refunds access"), the check's selects have visible labels, and the status line is a polite live region present from the start.
Related
- Pro
Access Token Hygiene Settings
Sign-in and securityAn access token settings panel that flags risky tokens (no end date, unused for 90 days, the admin scope, ending soon), gives a token an end date from a menu, and revokes the ticked ones after an alert dialog lists them.
- Pro
API Key Dialog
Account and securityA keys page with its create-key dialog shown open: a name, scopes and an expiry in the first step, then the secret shown once, masked behind an eye button, with a Copy button and a box that has to be ticked before Done.
- Pro
OAuth Apps Settings
API and webhooksAn OAuth apps settings window with a list of registered apps beside the chosen app's client ID, a masked secret with a confirmed Roll secret, redirect URIs that are checked when added, and grouped scopes with the consent sentence they produce.
- Pro
Webhook Endpoints Settings
API and webhooksA webhook endpoint settings sheet open over the endpoint list: an https URL, an event tree with mixed-state group checkboxes, a signing secret with Roll secret, and recent deliveries where a failed one can be resent with its signature worked out in the browser.
- Pro
API Rate Limit Tiers Settings
API and webhooksA matrix of API limits with the plans across and a number field in every cell, a daily capacity worked out under each plan and a guard that stops a higher plan from allowing less than the plan before it.
- Pro
CORS Allowed Origins Settings
API and webhooksA CORS settings panel that checks its own origin list for four unsafe patterns, each with a Fix button that rewrites the list, plus origin rows with an environment tag, a validating add form and a policy band for credentials and preflight cache.