# issue-scoped-api-tokens

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

- **Space:** token-management-public (https://github.com/Tech-Realm/space-token-management-public/tree/main/issue-scoped-api-tokens)
- **Level:** L2 (as the registry reports it)
- **Keys it needs (names only):** TOKENS_ADMIN_SECRET
- **Tools:** python3
- **Routes:** stdlib-sqlite, litellm-virtual-keys; checks: 3
- **Uses:** new (no recorded use yet)
- **Install:** `logicpacks pack use token-management-public/issue-scoped-api-tokens` or MCP `get_pack token-management-public/issue-scoped-api-tokens`
- **Files:** CHANGELOG.md, code/tokens.py, outcome/EVIDENCE.md, outcome/checks.yaml, outcome/results.json, pack.yaml, refs/refs.yaml, spec/SPEC.md, spec/source.md

## Purpose (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).



---

Canonical URL: https://logicpacks.io/packs/token-management-public/issue-scoped-api-tokens

Developed by TechRealm (techrealm.online), the software team. Operated by Al Jash Trading (Establishment), Abu Dhabi, since 1994, the legal entity that hosts and is responsible for the service. Economic licence CN-1030597, Abu Dhabi Registration Authority. Address: Office 5, Bani Yas West 4, Bani Yas, Abu Dhabi, UAE. Website: https://aljashtrading.com. Contact: hello@logicpacks.io, security@logicpacks.io, WhatsApp +1 713 632 2262 (https://wa.me/17136322262).

Machine-readable index: [/llms.txt](/llms.txt). Plain facts: [/about.md](/about.md). Safety: [/safety.md](/safety.md).
