Skip to content

Packs / token-management-public

issue-scoped-api-tokens

Issue, scope, verify, rotate and revoke per-user/team API tokens (hashed at rest, shown once, admin-gated)

L2 Checks passed 3 of 3 runsv1.0.0Tech-Realm/space-token-management-public

Install

logicpacks pack use token-management-public/issue-scoped-api-tokens
get_pack token-management-public/issue-scoped-api-tokens

The second line is the MCP tool call for the LogicPacks connector (Claude Code, Codex, Claude.ai and others). The first run of a pack someone else wrote asks for your yes.

Keys it needs (names only)

  • TOKENS_ADMIN_SECRET

Playbooks included

  • Spec: spec/SPEC.md (goal, steps, edge cases, don’ts)
  • Routes: stdlib-sqlitelitellm-virtual-keys
  • Checks: 3 in outcome/checks.yaml
  • Code: tokens.py
  • Tools: python3

Usage, last 8 weeks

New: no recorded use yet.

Purpose (from spec/SPEC.md)

Issue, scope, verify, rotate and revoke per-user/team API tokens (hashed at rest, shown once, admin-gated)

Goal

A user or team gets an API token with only the scopes it needs; the token can be verified, rotated and revoked, and the raw value is never stored.

Steps

  1. Set TOKENS_ADMIN_SECRET (vault) on the server; only the admin path can issue/rotate/revoke.
  2. Issue: tokens.py --db tokens.db issue <user> --team <team> --scopes read,llm [--ttl-min 120] [--cap-usd 5] [--rpm 60]; hand the raw token over once.
  3. Verify on every request: verify(raw, scope) -> ok / unknown / revoked / expired / scope / quota / rate.
  4. Rotate: rotate <id> issues a replacement with the same scopes and revokes the old one; Revoke: revoke <id> (idempotent).
  5. Export: list (no raw values) and usage-csv for dashboards.

Edge cases

  • Short-lived tokens: cap the TTL (24 h in our DSM pattern).
  • Clock skew on expiry: compare server time only.
  • A leaked token: revoke + rotate; the hash table makes lookups O(1) without storing secrets.

Don'ts

  • Don't store or log raw tokens; don't accept a minted token on the admin path.
  • Don't put tokens in URLs in production (headers only).