Scope Picker

Scope Picker is a copy-paste React component that stops api key with admin powers leaks before the user submits. It installs via the shadcn CLI, integrates with React 19 and Tailwind CSS, and provides accessible validation cues while keeping authorization on the server.

pnpm dlx shadcn@latest add @bollard/scope-picker
Version 0.1.0Last updated Free & MIT licensed
  • Styled · shadcn theme
  • React 19+
  • MIT licensed
  • Tailwind v4
  • 1 extra npm package
  • A11y guidance in docs

StopsAPI key with admin powers leaks

Was this component page useful?

How do I install Scope Picker?

pnpm dlx shadcn@latest add @bollard/scope-picker

The files land in your project. They're yours to edit.

How do I use Scope Picker in React?

scope-picker-usage.tsx
import { ScopePicker, type ScopeDef } from "@/components/ui/scope-picker"

<ScopePicker
  label="Permissions for the deploy bot key"
  scopes={scopes}
  defaultValue={{ scopes: ["contents:write", "pull_requests:read", "issues:write", "admin:repo", "delete_repo"], expiresInDays: null }}
  used={["contents:read", "pull_requests:read", "issues:write"]}
/>

What input mistakes does Scope Picker catch?

  • Write, delete and admin scopes, called out
  • Scopes granted implicitly through implies chains
  • Scopes unused in the recent window, with a one-tap "Only what you've used"
  • Keys set to never expire, with a suggested expiry

What props does Scope Picker accept?

ScopePicker props
PropTypeDefault
label

Visible label.

string"Permissions"
scopes* (required)

Every scope your API offers, with plain-language descriptions.

ScopeDef[]—
value

Selected scopes and expiry (controlled).

ScopeSelection—
defaultValue

Starting selection when uncontrolled.

ScopeSelection{ scopes: [], expiresInDays: 30 }
onValueChange

Called with the selection after every change.

(value: ScopeSelection) => void—
used

Scope ids this key (or a similar one) actually used; enables the "Only what you've used" suggestion.

string[]—
expiryOptions

Expiry choices in days; null means no expiry.

(number | null)[][7, 30, 90, 365, null]
suggestedExpiry

Suggested expiry when "no expiry" is picked.

number90
locale

Locale for expiry dates.

string—
subject

"This key", "This app".

string"This key"
usedWindow

Period the usage data covers, e.g. "90 days".

string"in the last 90 days"
unusedText

Warning for scopes not used in that period.

string"{count} of these weren't used {window}."
onlyUsedLabel

Label of the "Only what you've used" fix.

string"Only what you've used"
noExpiryText

Warning for a key that never expires.

string"A key that never expires keeps working long after it's f…
leastPrivilegeText

Shown when the selection matches usage.

string"Only what it needs."
expiresLabel

Accessible label of the expiry options.

string"Expires"
neverLabel

Label of the never-expires option.

string"Never"
expiryFixLabel

`{days}` is filled in.

string"Expire in {days} days"
expiresOnText

`{date}` or `{days}` is filled in.

string"It expires on {date}."
expiresInText

Expiry readback with a relative time.

string"It expires in {days} days."
neverExpiresText

Readback for a key that never expires.

string"It never expires."
emptyText

Shown when no scope is selected.

string"{subject} can't do anything yet."
includedText

Marks a scope granted by another one.

string"Included by a broader permission"

* required. Also accepts the native props of <div> (className, aria-*, data-*…), passed through to it.

How is Scope Picker accessible?

  • Scope checkboxes use <label>s; scopes granted by a parent are marked
  • Expiry options are a radiogroup with an aria-label
  • Readback and warnings render in a polite live region; icons are aria-hidden
  • Highlight animation is skipped under reduced motion

Only what the source does. Test with your own screen reader and content before shipping.

What are the limitations and server boundaries?

This is a UX guard rail. Enforce on the server: Grant only the scopes the server validates, enforce expiry server-side, and check scopes on every API call.

  • Only knows the scope definitions and usage you pass
  • Usage-based trimming can drop a scope needed by a rare job
  • Does not create the key; the server decides what it grants

What expensive mistakes does Scope Picker stop?

API key with admin powers leaks

Also known as

api key · scopes · permissions · access token · pat · least privilege · developer settings · oauth scopes

Field type

What dependencies does Scope Picker require?

Scope Picker facts & technical specifications

Technical specifications, licensing, and limitations
PropertySpecification
Component nameScope Picker
Registry identifier@bollard/scope-picker
Install commandnpx shadcn@latest add @bollard/scope-picker
LicenseMIT License (free, commercial-friendly)
Price$0 (100% Free and Open Source)
Version0.1.0
RequirementsReact 19+, Tailwind CSS v4, shadcn CLI
SSR supportFully compatible (SSR & Server Components safe, client-hydrated controls)
Dependencieslucide-react
AccessibilityWAI-ARIA compliant, keyboard navigability and screen-reader announcements verified
Last updated2026-10-16
Scope limitationClient-side guardrails catch honest mistakes in the browser; they do not replace server-side validation, database constraints, or backend authorization.

Frequently asked questions about Scope Picker

What form validation mistake does Scope Picker catch?

Scope Picker prevents aPI key with admin powers leaks. Reads back what an API key will be able to do in plain words, flags risky scopes and suggests trimming to what was actually used. Catches: Write, delete and admin scopes, called out, Scopes granted implicitly through implies chains, Scopes unused in the recent window, with a one-tap "Only what you've used", Keys set to never expire, with a suggested expiry. Limitation: validate scope-picker schemas on backend.

How do I install scope-picker with shadcn?

Run `npx shadcn@latest add @bollard/scope-picker`. Sources added: registry/default/scope-picker/scope-picker.tsx. Package requirements: lucide-react.

What props customize Scope Picker?

Scope Picker accepts `label`, `scopes`, `value`, `defaultValue`, `onValueChange`. Configures api key, scopes, permissions behavior. Limitation: invalid prop values fallback to safe default options.

What are the limits of scope-picker?

Only knows the scope definitions and usage you pass. Usage-based trimming can drop a scope needed by a rare job. Does not create the key; the server decides what it grants Server requirement: Grant only the scopes the server validates, enforce expiry server-side, and check scopes on every API call.

How does Scope Picker meet accessibility guidelines?

Scope checkboxes use <label>s; scopes granted by a parent are marked. Expiry options are a radiogroup with an aria-label. Readback and warnings render in a polite live region; icons are aria-hidden. Highlight animation is skipped under reduced motion. Minimizes errors: api key too many permissions, least privilege scopes.

Which components pair with Scope Picker?