fix: add downstream token API for OAuth broker migration#52
fix: add downstream token API for OAuth broker migration#52abhijitjavelin wants to merge 2 commits intomainfrom
Conversation
New endpoints for storing/retrieving encrypted per-user downstream
OAuth tokens (GitHub, Slack, etc.) for MCP server authentication.
Migrates token broker from admin to zeroid.
- domain/downstream_token.go: model + status type
- migrations/007: downstream_tokens table + indexes
- store/postgres: CRUD (Upsert, Get, Delete, ListByUser, Update)
- service: encrypt/decrypt (AES-256-GCM), auto-refresh
- handler: 4 endpoints under /api/v1/downstream-tokens/
- config: EncryptionKey in TokenConfig
- server.go: wire service + repo + routes
API:
POST /api/v1/downstream-tokens/{server_slug} — store token
GET /api/v1/downstream-tokens/{server_slug} — fetch decrypted
DELETE /api/v1/downstream-tokens/{server_slug} — disconnect
GET /api/v1/downstream-tokens — list connected
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request introduces a downstream token management system to store and retrieve encrypted third-party OAuth tokens. It includes a new database schema, a repository layer, a service layer featuring AES-256-GCM encryption and automatic token refresh, and corresponding REST API endpoints. Feedback highlights several critical improvements: ensuring the encryption key is correctly mapped to environment variables, removing hardcoded security defaults, implementing timeouts for external HTTP requests, and using synchronization mechanisms like singleflight to prevent race conditions during token refreshes. Additionally, the mandatory requirement for tenant-specific headers in API handlers should be re-evaluated.
…check - Add ZEROID_TOKEN_ENCRYPTION_KEY to env mapping in config - Remove hardcoded default encryption key — service disabled if not set - Return 503 from handlers when encryption key not configured - Use http.Client with 10s timeout for OAuth refresh (not default client) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
New API endpoints for storing/retrieving encrypted per-user downstream OAuth tokens. This migrates the token broker from admin's
user_mcp_tokensto zeroid'sdownstream_tokens.Endpoints
/api/v1/downstream-tokens/{server_slug}/api/v1/downstream-tokens/{server_slug}/api/v1/downstream-tokens/{server_slug}/api/v1/downstream-tokensChanges
domain/downstream_token.go— modelmigrations/007— table + indexesinternal/store/postgres/downstream_token.go— CRUDinternal/service/downstream_token.go— encrypt/decrypt (AES-256-GCM), auto-refreshinternal/handler/downstream_token.go— Huma handlersconfig.go—EncryptionKeyinTokenConfigserver.go— wire service, repo, routesTest plan
🤖 Generated with Claude Code