Repository navigation
workers/mcp: connect an agent with a FacturX account, no key to paste - #18
Merged
Merged
Conversation
The consent page offers « Se connecter avec mon compte FacturX » when WEB_ORIGIN and both agent-connect secrets are set. The Worker approves the consent, binds the flow to the browser with the OAuth library's beginUpstream (__Host- cookie), signs a consent token and sends the browser to facturxapi.com/connecter-agent. On the fixed return /authorize/retour, finishUpstream refuses any other browser before the code is exchanged server to server. The paste field stays as a fallback. The wrangler comment states the real deploy rule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t the API's scopes, tests Identifiers the API would refuse (client_id or redirect host over 200 characters) are refused before anything is bound to the browser; only the displayed name is shortened. The scopes given to the agent are also limited to those the API recorded for the key. Tests for the checks after finishUpstream and for the French restart page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 26, 2026
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.
What this does
On the hosted MCP server's consent page, a user who already has a FacturX account can authorize an agent in one click: « Se connecter avec mon compte FacturX ». The API creates a dedicated key for the agent. The key never appears in the browser, in a URL or on a page. Pasting an API key stays available as a fallback.
The button is shown only when
WEB_ORIGINand both secrets below are configured. Without them, the page is unchanged.Flow
POST /authorizewithdecision=facturx:beginUpstream, which creates a 256-bitstate, stores the request encrypted in KV for 600 s, and sets a__Host-cookie holding the state's hash;303to the fixed addresshttps://facturxapi.com/connecter-agent#consent=<token>. The token is in the fragment./authorize/retour?state=…&code=….GET /authorize/retour:finishUpstreamrefuses any browser that did not start this flow, before anything else;/api/v1/internal/agent-connections/exchange, dedicated secret);Security properties
Configuration
WEB_ORIGIN(var):https://facturxapi.com. It must be a bare https origin; anything else disables the button.AGENT_CONNECT_SIGNING_SECRETandAGENT_CONNECT_EXCHANGE_SECRET(wrangler secrets, at least 32 characters): the same values as the API's.wrangler.jsonccomment now states the actual rule: no deployment from a branch or pull request; the Worker is deployed only at a release, after review. This PR deploys nothing.Tests
node --experimental-strip-types --test test/*.test.ts: 32 passed. That is 12 new, plus the 20 existing ones (the paste fallback is unchanged).tsc --noEmit: clean.The new tests cover:
303to the fixed page, with a?web=parameter ignored;finishUpstream;Mutants, each run and then reverted. Every one makes at least one test fail:
finishUpstreamremoved.End-to-end proof (local)
This ran against a local FacturX API and web site, and this Worker under
wrangler dev. A browser reached them through their real https host names (Playwright routing), so the__Host-cookies behaved as in production. No request reached a real host.__Host-oauth-upstream-…: Secure, HttpOnly, SameSite=Lax, host-only200,scope: mcp:read mcp:writetools/listwith that token200, the 4 FacturX tools400: « La connexion n'a pas abouti… Aucune clé n'a été créée. »The local run used
compatibility_date2026-10-13, the newest supported by the localworkerd. The committed config is unchanged.