Repository navigation
feat(oauth): identify CodeWork with a Client ID Metadata Document and unify loopback callback - #189
Merged
Merged
Conversation
… unify loopback callback
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.
Identifies CodeWork to external OAuth authorization servers (MCP servers and Connectors) using a Client ID Metadata Document (CIMD) hosted on
https://codework.sh/oauth/, with per-server documents whenissis unsupported and Dynamic Client Registration (DCR) as the fallback, and unifies all CodeWork OAuth loopback callbacks on/oauth/callback.This allows signing in to OAuth servers that disable DCR (such as Clerk) without configuring a manual
clientId, isolates callbacks per resource when RFC 9207issis absent (RFC 9700 §4.4.2.2), and preserves127.0.0.1->localhostredirect rewrites at token exchange.Hosted Metadata Documents (
sites/www)sites/www/src/worker.ts) attached to the existingStaticSiteinsites/www/alchemy.run.tsviaassets.runWorkerFirst: ["/oauth/*"].GET https://codework.sh/oauth/client.json(shared) andGET https://codework.sh/oauth/<id>/client.json(per-server, validated against/^[A-Za-z0-9_-]{12}$/, returning404otherwise) withapplication/json,Cache-Control, and publicGETCORS, listing bothhttp://127.0.0.1/oauth/callback[/:id]andhttp://localhost/oauth/callback[/:id].Shared Identity Policy & Harness MCP OAuth (
packages/harness)packages/harness/src/mcp/cimd.ts(exported asOAuthCimdfrom@codeworksh/harness/effect) with the deterministic 12-character resource fingerprint (callbackId), CIMD selection rule (configured -> shared CIMD if iss -> per-server CIMD if !iss -> DCR), and callback redirect matching (allowing127.0.0.1->localhoston the bound port and exact path)./callbackto/oauth/callback(existingmcpauth.jsonDCR grants still refresh without disruption; new browser logins register or use CIMD on/oauth/callback).McpOAuth.signIn, keeps CIMD client IDs out of persisted DCRclientInformation(storingtokenClientIdfor refreshes so future sign-ins re-decide from discovery), arms the loopback waiter before opening the browser, and sends the exact observedredirect_urion exchange.Connectors OAuth, CLI & Desktop (
packages/codework,apps/server,apps/web,packages/aikit)packages/codework/src/connector/oauth.tsto readissuer,client_id_metadata_document_supported,token_endpoint_auth_methods_supported, andauthorization_response_iss_parameter_supported, selecting CIMD without requiringregistration_endpoint.connections.oauth.start/connections.oauth.finish) so loopback listeners stay on the browser's machine across CLI,--server, LAN, Tailscale, and Relay; clients arm the host-chosen callback path before opening the browser and forward the full observed callback URL so the host validatesstate, path,iss, andlocalhostrewrites before consuming pending state.apps/server/src/oauth-loopback.tsandpackages/aikit/src/oauth/interactive.tsto a clean, card-free full-bleed layout supporting both light and dark modes, with escaped error HTML.Docs & Plugin Comments (
packages/plugin,docs/internals)/oauth/callback, and custom override behavior inpackages/plugin/src/plugin/mcp.ts,docs/internals/08_plugins.md, anddocs/internals/09_server.md.Testing
vp run verify(vp check, builds, package typechecks,knipfiles/deps/exports): passed (0 issues).apps/server,apps/web,sites/www): passed.packages/harness/test/mcp.oauth.test.ts(2/2 passed, artifactpackages/harness/test/__artifacts__/mcp.oauth.cimd.json): covers shared CIMD +iss, per-server CIMD withoutiss, DCR fallback,clientId/clientNameoverrides,127.0.0.1->localhostrewrite, wrong-path rejection, mismatchedissrejection, and refreshing legacy/callbackDCR grants.packages/codework/test/connector.test.ts(5/5 passed, artifactpackages/codework/test/__artifacts__/connector.cimd.json): covers shared and per-server CIMD without DCR, bare-code / bad-iss/ wrong-path rejection,localhostrewrite, and CIMD refresh.packages/codework/test/cli.mcp.oauth.test.ts(9/9 passed).apps/server/test/oauth-loopback.test.ts(1/1 passed, artifactapps/server/test/__artifacts__/oauth-loopback.json): covers per-server path acceptance, wrong-path rejection with valid state,localhostrewrite preservation, and HTML escaping.sites/www:200onhttps://codework.sh/oauth/client.jsonandhttps://codework.sh/oauth/-zkQPH0u2sKR/client.json,404onhttps://codework.sh/oauth/test/client.json, and intact static site +404page.cimd: true,iss: true, no DCR) acceptshttps://codework.sh/oauth/client.json(302to sign-in).clientId: "https://codework.sh/oauth/client.json"persisted inconnections.dband the new callback page rendered cleanly.Built with Gemini (Antigravity).
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.