Skip to content

API key management — production auth for admin and public endpoints #39

Description

@leocagli

Problem

All API routes are currently unprotected. There is no authentication for the admin console or the public API. This blocks production use.

Design

Admin key (full access)

Generated on first boot, stored as ADMIN_API_KEY env var.
Required on: all /admin/* routes, /api/agents write operations.

Service keys (scoped)

Created by admin via:

POST /api/admin/keys
{
  "name": "my-integration",
  "scopes": ["x402:quote", "x402:settle", "agents:read"],
  "expiresAt": "2027-01-01"
}

Returns: { key: "osk_live_abc...", id: "key_123" }

Request auth

Authorization: Bearer osk_live_abc...

Or for simple integrations: ?apiKey=osk_live_abc...

Rate limits

Tier Requests/min
No key 10
Free 60
Pro 600
Admin unlimited

Rate limits enforced via Vercel KV (sliding window counter).

Admin UI

  • Keys management page in admin console
  • Show: name, scopes, last used, request count, status
  • Revoke / rotate buttons

Files to create

  • lib/auth/api-keys.ts — key generation, validation, rate limiting
  • lib/auth/middleware.ts — Next.js middleware for route protection
  • middleware.ts — root middleware applying auth
  • app/admin/keys/page.tsx

🎁 Evidencia visual = reward extra

  • Si tu PR incluye video demo o capturas de pantalla mostrando la funcionalidad pedida funcionando end-to-end, va a ser considerado para rewards de GrantFox en esta issue. No es obligatorio, pero suma mucho para la evaluación.

Metadata

Metadata

Assignees

No one assigned

    Labels

    GrantFox OSSPart of the GrantFox OSS campaignMaybe RewardedMay be eligible for GrantFox rewardOfficial CampaignOfficial GrantFox campaign issuearea: infraDatabase, queues, observabilityclaimedIssue tomado por un contribuidor (via /assign)milestone: v0.3x402 Production Rails

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions