feat(api): self-serve API token management in Settings → Account#5750
Open
holden093 wants to merge 3 commits into
Open
feat(api): self-serve API token management in Settings → Account#5750holden093 wants to merge 3 commits into
holden093 wants to merge 3 commits into
Conversation
Backend:
- GET /api/tokens/self — list current user's own tokens
- POST /api/tokens/self — create a token (cookie-only, owner forced)
- DELETE /api/tokens/self/{id} — revoke own token
- All self-serve endpoints use require_user (reject bearer tokens)
Frontend:
- 'Personal API Tokens' card in Settings → Account tab
- List existing tokens with name, prefix, scopes, last used, revoke button
- Create flow with scope checkboxes, one-time token reveal + copy
- Styled confirm dialog before revocation
…rve tests - Return 404 (not 403) when a user tries to delete another user's token via the self-serve endpoint, closing an information leak. - Add tests covering: bearer-token rejection (403), owner isolation (list only returns own tokens), not-yours delete → 404, unknown scope rejection (400), and owner forced from session on create.
Contributor
Author
Heads-up: the failing
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a self-serve API token management flow so regular users can create, list, and revoke their own API tokens from the Account settings page — no admin required. Previously,
POST /api/tokenswas gated behindrequire_admin, and the only user-facing token creation happened as a side effect of setting up a Codex/Claude agent in the Integrations panel.Three cookie-only
/api/tokens/selfendpoints (GET, POST, DELETE) let users manage their own tokens with owner-scoping enforced server-side. A new "Personal API Tokens" card in Settings → Account provides a UI with scope checkboxes, one-time token reveal + copy, and revoke with confirmation.Security:
require_userrejects bearer tokens (403 — no token bootstrapping). Owner is forced server-side from the session, never trusted from the client. Tokens are isolated per-user; one user cannot see, modify, or delete another's tokens.Target branch
dev, notmain.Linked Issue
Fixes #4658
Type of Change
Checklist
dev/api/codex/capabilities, and revocation on a production instance.How to Test
/api/companion/pingand/api/codex/capabilitiesto confirm it works and has the correct scopes.401 Invalid API token)./api/tokensendpoints./api/tokens/self(returns 403).Visual / UI changes
--bg,--fg,--border,--accent,--red) and button classes (admin-btn-add,admin-btn-delete,admin-btn-sm). No new colors or spacing units.Screenshots