Repository navigation
Merged
Conversation
… can sign in to /api/agent/mcp Any unauthenticated request to /api/agent/mcp is now 401 with WWW-Authenticate: Bearer resource_metadata=... Existing b1dz_agent_ keys work unchanged. Each OAuth grant is backed by its own agent_tokens sub-account (read-only unless the user grants a capped trading budget on the consent screen), so an OAuth token never has wider rights than an agent key. Ported from profullstack/threatcrush#450. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ThreatCrush Security Scan7 finding(s) MEDIUM: 7
Snippets are redacted; ThreatCrush never prints matched credential material. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Makes the b1dz MCP server (
https://b1dz.com/api/agent/mcp) listable in the Claude Connectors Directory and usable as a ChatGPT app: OAuth 2.1 per the MCP authorization spec, ported from profullstack/threatcrush#450 (Supabase variant as in smshub#140 / crawlproof.com#449).What
WWW-Authenticate: Bearer resource_metadata="https://b1dz.com/.well-known/oauth-protected-resource", scope="mcp"; a bad credential addserror="invalid_token". GET is 401 signed out, 405 signed in./.well-known/oauth-protected-resource(+ path-suffixed form),resourceexactlyhttps://b1dz.com/api/agent/mcp;/.well-known/oauth-authorization-server(+ suffix) and/.well-known/openid-configuration.POST /api/oauth/register: RFC 7591 DCR, public clients only (none); https redirects, http loopback on any port (RFC 8252)./oauth/authorize: consent page naming the client. Signed out:/login?next=round trip (password or CoinPay, which binds bysub). The user picks read-only (default) or a capped crypto trading budget per day/week/month. The decision posts JSON to/api/oauth/authorizewith the cookie session (same origin only) or a Bearer Supabase session, and the page navigates itself (a form POST that 303s to claude.ai would be blocked by our CSPform-action).iss(RFC 9207) on every redirect.POST /api/oauth/token: form-encoded (or JSON) authorization_code with PKCE S256, single-use 5-minute code bound to client + redirect + user; rotating refresh tokens (90 d), access tokensb1dz_oat_(1 h).POST /api/oauth/revoke(RFC 7009).agent_tokensrow (" (connected app)"), created at code exchange with the scopes/budget chosen on consent, and the access token resolves to the sameAuthedAgentab1dz_agent_key does, so every tool still goes through agent-trade.ts (scope, allowlist, per-token budget, audit log). It appears with the user's agent tokens in Settings; revoking either side ends the grant. OAuth tokens are accepted only by the MCP route.b1dz_agent_keys work unchanged.title+readOnlyHint/destructiveHint/idempotentHint/openWorldHintannotations (place_order is destructive + open-world); tools/list carriesresultType/ttlMs/cacheScope; protocol version negotiation (2025-06-18, 2025-03-26, 2024-11-05);instructions./oauth,/register,/authorize,/tokenare public, so an MCP client's DCR fallback gets a 404, never the HTML login page.20261111150000_mcp_oauth.sql:oauth_clients,oauth_codes,oauth_tokens(hashes only, RLS on, service role only).Tests
apps/web/src/app/api/oauth/__tests__/oauth-flow.test.ts(16): discovery, 401 + resource_metadata (initialize and GET), invalid_token, oldb1dz_agent_key still works, DCR + refusals, consent auth (signed out, cross-site cookie refused, Bearer session), PKCE required, deny, loopback port, full code -> token -> tools/list -> refresh rotation -> replay refused -> revoke, read-only default vs granted budget, wrong verifier / reused code / redirect mismatch, revoking the agent token ends the grant, hashes only.route.test.tsupdated for the 401, annotations and cache fields.pnpm typecheck(68 tasks) andpnpm testgreen locally; web suite 190 passed.🤖 Generated with Claude Code