Public: anyone can read this; the crew can change it.
OAuth for the MCP, step two: an authorize page and a PKCE token exchange that mint the same ro/rw forge tokens #818
Step two of the MCP's OAuth is in. A person can approve a client on a consent page, and the client trades its one-time code for the same ro/rw forge token Settings mints. tsc is clean.
stopped closed without shipping
Sign in to join this conversation.
new above
offline
Step two of the MCP's OAuth is in. A person can approve a client on a consent page, and the client trades its one-time code for the same
ro/rwforge token Settings mints.tscis clean. The newtest/oauth-flow.test.ts(12 tests) andtest/oauth-discovery.test.tspass, andmcp.test.tsandcheck-list.test.tsalso pass in the same run. I did not run the full gate.test/tokens.test.tsfails here (repo creation) with and without these changes, so it is not caused by them. I only ran the tests outside the sandbox, because they need unix sockets.GET /oauth/authorizesends a signed-out visitor to/signin?next=…and back. Signed in, it shows the client's name and redirect host, a choice ofroorrw, a token name, and a lifetime (until revoked by default, or a year, 30 days or a day). The POST is same-origin checked, needs a session, and re-validates every parameter. The page and the redirect carryno-storeandno-referrer.access_deniedwithstate, andstatecomes back on allow.POST /oauth/tokentakesauthorization_codewith PKCES256, as a form or JSON. It mints throughcreateTokenwithexpiresAtwhen a lifetime was chosen, and the token is listed and revocable in Settings. Every refusal isinvalid_grant.rotoken callsappsand is refusedtell. The file is in the gate.docs/MCP.mdhas the OAuth flow, the Claude app (callbackhttps://claude.ai/api/mcp/auth_callback) and Grok's custom connectors. Migration 54 addsoauth_code.I did not touch
src/core/tokens.ts(createTokenalready takesexpiresAt), and I added no dependencies. I left out refresh tokens, CORS orOPTIONSon the token endpoint, and client authentication beyondnone. Since there are no refresh tokens, a token with a short lifetime simply stops working when it expires, which is why the default is no expiry.To try it, register a client at
/oauth/register, open/oauth/authorize?response_type=code&client_id=…&redirect_uri=…&code_challenge=…&code_challenge_method=S256&state=…while signed in, thenPOST /oauth/tokenwith the returned code andcode_verifier.Closes #574