Skip to content

feat: add DB-backed token management to SQLiteAdapter#18

Merged
cuibonobo merged 3 commits into
mainfrom
claude/nice-ptolemy-Iai17
Jun 16, 2026
Merged

feat: add DB-backed token management to SQLiteAdapter#18
cuibonobo merged 3 commits into
mainfrom
claude/nice-ptolemy-Iai17

Conversation

@cuibonobo

Copy link
Copy Markdown
Member

Summary

  • Adds a tokens table to the SQLite schema with (id, token_hash, entity_id, label, created_at, expires_at) columns and idx_tokens_hash index for fast lookup
  • Exports TokenInfo type from @haverstack/adapter-sqlite
  • Adds four new methods to SQLiteAdapter:
    • createToken(entityId, opts?) — generates a random token, stores SHA-256 hash, returns { id, token } (plaintext exposed only once)
    • lookupToken(token) — hashes and looks up; returns { entityId } or null (respects expires_at)
    • listTokens() — returns all TokenInfo objects without plaintext values
    • revokeToken(id) — deletes by token ID

Motivation

The server's OWNER_TOKEN env var is the single bootstrap credential. All other tokens are issued and revoked at runtime via the /tokens API — no server restarts required. Storing hashes (SHA-256) means a DB breach doesn't expose usable tokens.

Test plan

  • createToken returns a 16-char hex id and 64-char hex plaintext token
  • lookupToken returns entityId for a valid token
  • lookupToken returns null for an unknown token
  • lookupToken returns null for an expired token
  • lookupToken returns entityId for a non-expired token
  • listTokens returns all tokens without plaintext values
  • revokeToken removes the token so lookupToken returns null
  • label and expiresAt round-trip through listTokens

Generated by Claude Code

Adds a `tokens` table (id, token_hash, entity_id, label, expires_at)
with a hash index, and four new methods: createToken, lookupToken,
listTokens, revokeToken. Tokens are stored as SHA-256 hashes of the
raw token value; the plaintext is returned only at creation time.
Also exports the TokenInfo type for use by the server.
@cuibonobo cuibonobo merged commit 56a8090 into main Jun 16, 2026
@cuibonobo cuibonobo deleted the claude/nice-ptolemy-Iai17 branch June 16, 2026 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant