Skip to content

fix: add downstream token API for OAuth broker migration#52

Closed
abhijitjavelin wants to merge 2 commits intomainfrom
feat/downstream-tokens
Closed

fix: add downstream token API for OAuth broker migration#52
abhijitjavelin wants to merge 2 commits intomainfrom
feat/downstream-tokens

Conversation

@abhijitjavelin
Copy link
Copy Markdown

Summary

New API endpoints for storing/retrieving encrypted per-user downstream OAuth tokens. This migrates the token broker from admin's user_mcp_tokens to zeroid's downstream_tokens.

Endpoints

Method Path Purpose
POST /api/v1/downstream-tokens/{server_slug} Store encrypted token
GET /api/v1/downstream-tokens/{server_slug} Fetch decrypted token
DELETE /api/v1/downstream-tokens/{server_slug} Disconnect
GET /api/v1/downstream-tokens List connected servers

Changes

  • domain/downstream_token.go — model
  • migrations/007 — table + indexes
  • internal/store/postgres/downstream_token.go — CRUD
  • internal/service/downstream_token.go — encrypt/decrypt (AES-256-GCM), auto-refresh
  • internal/handler/downstream_token.go — Huma handlers
  • config.goEncryptionKey in TokenConfig
  • server.go — wire service, repo, routes

Test plan

  • Store token → encrypted in DB
  • Get token → decrypted correctly
  • List tokens → returns status without secrets
  • Delete token → returns 404 on subsequent get
  • Auto-refresh with expired token + refresh_token

🤖 Generated with Claude Code

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>
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
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