mirror of
https://github.com/Dvorinka/Containr.git
synced 2026-10-28 15:51:26 +00:00
feat: personal access tokens with scoped bearer auth
Add cnp_ personal access tokens so the CLI, MCP server, and external agents authenticate without a browser session — the agent-first spine from ROADMAP2 phase A. Modeled on agent_auth_tokens: raw token shown once, only SHA-256 hash stored. - user_tokens table (goose migration + sqlc), name/prefix/scope/expiry, owner-scoped revoke, last_used_at stamping - middleware: cnp_ bearer resolution, read scope gates mutations with 403 SCOPE_INSUFFICIENT, non-admin scopes cap is_admin even for admin owners — a token never outranks its scope or its owner - GET/POST/DELETE /api/v1/user/tokens + OpenAPI + generated types - Settings UI: create with scope/expiry pickers, one-time token display with copy, list with last-used/expiry, confirm-revoke - docs: OPERATIONS.md section, README feature line Verified end-to-end against live Postgres: create/list/revoke, read scope blocks PUT (403), write PAT on admin owner blocked from admin routes (403), admin scope works, revoked token returns 401. Authored By: TDvorak <[email protected]>
This commit is contained in:
1 parent
f9ae5b962c
commit
e881747388
17 files changed
+1141
-30
No files matched your search
@@ -993,6 +993,34 @@ export async function revokeAgentToken(id: string): Promise<void> {
|
||||
await requestJson(`/agent-tokens/${id}`, { method: 'DELETE' });
|
||||
}
|
||||
|
||||
export type UserToken = components['schemas']['UserToken'];
|
||||
export type UserTokenCreated = components['schemas']['UserTokenCreated'];
|
||||
export type UserTokenScope = 'read' | 'write' | 'admin';
|
||||
|
||||
export async function createUserToken(input: {
|
||||
name: string;
|
||||
scope?: UserTokenScope;
|
||||
expiresInDays?: number;
|
||||
}): Promise<UserTokenCreated> {
|
||||
return requestJson<UserTokenCreated>(`/user/tokens`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
name: input.name,
|
||||
scope: input.scope ?? 'write',
|
||||
expires_in_days: input.expiresInDays ?? 0,
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
export async function listUserTokens(): Promise<UserToken[]> {
|
||||
const payload = await requestJson<{ tokens?: UserToken[] }>(`/user/tokens`);
|
||||
return payload.tokens ?? [];
|
||||
}
|
||||
|
||||
export async function revokeUserToken(id: string): Promise<void> {
|
||||
await requestJson(`/user/tokens/${id}`, { method: 'DELETE' });
|
||||
}
|
||||
|
||||
export async function createProject(input: CreateProjectInput): Promise<ProjectEntity> {
|
||||
const payload = await requestJson<RawProject | { project?: RawProject }>(`/projects`, {
|
||||
method: 'POST',
|
||||
|
||||
Reference in new issue
Block a user