Repository navigation
feat(mcp): the consent page where a person connects an app - #2272
Merged
Merged
Conversation
PR 4 of MCP over OAuth (ansvisor#2141), stacked on feature/mcp-oauth-endpoints (ansvisor#2262). Still behind MCP_OAUTH_ENABLED: the authorize endpoint and the page answer 404 while it is off. - /api/oauth/authorize checks the request: an unknown client or a redirect URI it never registered ends on Ansvisor's own page and is never redirected to; after that, errors go back to the app with state and iss (response_type code, PKCE S256, our resource). A good request is kept 10 minutes and the person goes on to /oauth/consent with its id alone. 60 requests an address in ten minutes. - /oauth/consent (the approved mockup's screens 1 to 6): sign in first, with a line naming the app on the sign-in page; then the app (a known one named by where its code goes, claude.ai or chatgpt.com; any other by its own name, marked not checked, with a warning when it runs on this computer), the person, workspace, plan and brands, and Read plus "Make changes you ask for". The free trial and an ended plan show why instead of Allow (an admin gets Choose a plan); no workspace yet says so; a request that can't be used is explained and goes nowhere. - Allow and Cancel are server actions: the request must still be pending and the person's who first opened it, and Allow reads the plan again. Allow writes a one-time code (5 minutes) for the client, redirect URI, PKCE challenge and resource, with the scopes left ticked, and sends the app code, state and iss; Cancel sends access_denied. Both use the request up and are logged. Switch account signs out and comes back. - The page is never framed (X-Frame-Options, frame-ancestors), cached or given as a referrer. AuthShell takes an aside and can drop its pitch. - The known apps' list moves to its own module, shared with Settings. Part of ansvisor#2141. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
9 of 13 tasks
9 of 13 tasks
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.
Summary
PR 4 of the MCP over OAuth plan (#2141). Based on
main: #2260, #2261 and #2262 are merged, andupstream/mainis merged into this branch, so the diff is this PR alone. It also merges cleanly into currentmain(f947d77).It adds the authorization endpoint and the consent page: screens 1 to 6 of the approved mockup. It is still behind
MCP_OAUTH_ENABLED: while the flag is off, the endpoint and the page answer 404, and the sign-in page is unchanged.GET /api/oauth/authorize(web/src/app/api/oauth/authorize/route.ts,web/src/lib/mcp-oauth/authorize.ts)client_id, thenredirect_uri, which must be one the client registered (exactly, or loopback on any port). If the client has only one, it may be left out./oauth/consent?error=unknown_client|invalid_redirect_uri) and is never redirected to the address it names (RFC 6749 §4.1.2.1).stateandiss(RFC 9207):unsupported_response_type(onlycode);invalid_request(PKCE withcode_challenge_method=S256is required,plainis refused, andstatemay be at most 1,000 characters);invalid_target(a resource other than ours; none means ours).mcp:*scope asked for means both. Unknown ones such asoffline_accessare ignored.oauth_authorization_requests. The person goes on to/oauth/consent?request=<id>: the id is all the address holds. Expired requests are swept.rate_limitedpage.The consent page (
web/src/app/[locale]/(marketing)/oauth/consent/page.tsx,web/src/lib/mcp-oauth/consent.ts,web/src/components/oauth/consent-card.tsx)/sign-in?next=…and comes back. Google sign-in comes back too, through the existingnextcookie. Screen 1: the sign-in page shows "Sign in to connect Claude to Ansvisor. Next, you'll choose what it can do." It says "an app" for one Ansvisor hasn't checked.access_denied.plan-facts.Allow and Cancel (
web/src/lib/mcp-oauth/consent-actions.ts, server actions)ans_oac_, 5 minutes, stored as sha256) for the request's client, redirect URI, PKCE challenge and resource, with the scopes left ticked (reading always), for the organization the person is in now;consent_granted;redirect_uri?code=…&state=…&iss=….access_deniedwithstateandiss. The request is used up, and the log recordsconsent_denied,blocked_trialorblocked_ended.assertWritable); the plan rule here is the sign-in one. They live inlib/mcp-oauth, notlib/actions, sosubscription-guard-coveragedoesn't list them.Other changes
web/next.config.ts:/oauth/*(and/en/oauth/*) getX-Frame-Options: DENY,frame-ancestors 'none',Referrer-Policy: no-referrer(the request id never leaks to the app) andCache-Control: no-store.AuthShellgains an optionalaside(here, "Signed in as …" in the header) andpitch={false}, which centres the card.ctais now optional. The sign-in and sign-up pages are unchanged.web/src/lib/mcp-oauth/known-apps.ts: the known apps' list, also used by Connected apps (PR 6, built on feat(mcp): accept OAuth access tokens at /api/mcp, behind MCP_OAUTH_ENABLED (00510) #2261). The file is identical in both branches, so they merge cleanly.web/messages/en.json: theoauthConsentnamespace, andauth.oauthSignInLine/oauthSignInLineUnchecked.Tests
authorize/route.test.ts(14 tests): a good request, the client's only redirect URI, loopback on any port, the cases that end on Ansvisor's page without redirecting, the cases sent back withstateandiss, scopes, the limit, and 404 while off.consent.test.ts(18 tests): the view for a known and an unchecked app; Selected brands; trial, ended, Enterprise trial, self-hosted and no workspace; sign-in, bad, unknown and expired requests; the first-person claim; the sign-in line's app. Allow → token endpoint →checkAccessToken, end to end. Read-only when unticked; no code on a plan that stopped; another person, signed out, spent request and flag off; Cancel withstate/iss; the blocked log; Switch account.consent-card.test.tsx(12 tests): every card and error, as rendered.No Help or docs change: nothing is switched on. Help and docs come with PR 7.
Related issue
Part of #2141
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
cd web && npx vitest run src/app/api/oauth src/lib/mcp-oauth src/components/oauth.MCP_OAUTH_ENABLED=true,NEXT_PUBLIC_APP_URL=http://localhost:3000, and 00510 applied to the dev database.http://localhost:3000/api/oauth/authorize?response_type=code&client_id=<id>&redirect_uri=http://127.0.0.1:9999/cb&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM&code_challenge_method=S256&state=x':''http://127.0.0.1:9999/cb?code=ans_oac_…&state=x&iss=…;/api/oauth/tokenwithcode_verifier=dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk.redirect_uri=https://evil.example/cb: you land on "This connection request can't be used", and nothing goes to evil.example.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)help/(or no user-visible change) — see help/README.md: nothing is switched on; Help comes with PR 7Checks run:
yarn buildpasses (with CI's placeholder env).upstream/main:src/components/oauth,src/components/auth,auth-next,src/lib/mcp-oauth,src/app/api/oauth,src/app/api/mcp,src/lib/mcp, bothmcp-authtests,embed-hints,subscription-guard-coverageandbrand-access-functions: 73 files, 651 tests passed.Generated by Claude Code