Repository navigation
fix(auth): a new CIMD authorization keeps the user's other grants - #442
Merged
mattzcarey merged 1 commit intoNov 25, 2026
Merged
Conversation
A CIMD client ID and its redirect URI are shared by every connection a hosted client holds (one metadata URL, one callback), so the provider's default grant replacement revoked a user's other live connections whenever they authorized again. Their next refresh failed with 'Grant not found'. Registered (DCR) clients get a client ID per install and keep replacement.
|
+1 Just confirming that I repro-ed the bug that revokes access when a 2nd connection is established.
|
mattzcarey
approved these changes
Nov 25, 2026
mattzcarey
left a comment
Member
There was a problem hiding this comment.
Reviewed locally: the new test fails without the override, and typecheck, lint and the suite pass. cloudflare/workers-oauth-provider#434 makes this the library default; drop the override when we bump to it.
sam-huckaby
pushed a commit
to cloudflare/workers-oauth-provider
that referenced
this pull request
Nov 25, 2026
A new authorization from a Client ID Metadata Document client no longer revokes the user's other grants from that client. `revokeExistingGrants` now defaults to `false` for a client resolved from a metadata document, and `true` means the same for every client: revoke the user's other grants for this client and resource. Builds on #433 by @matthewhenry1 and replaces it; released as a minor because the meaning of `true` changes for CIMD clients. A CIMD `client_id` is shared by every installation and connection of the client, and nothing in the request tells them apart: - #299 limited default revocation to grants from the same redirect URI, but a hosted client uses one https callback for all its connections, so signing in a second agent revoked the first, which then failed with `invalid_grant: Grant not found` - #433 turned the default off but kept the redirect URI rule under `true`, so one option meant two things depending on the client ID - a URL `client_id` stored in KV with `clientIdMetadataDocumentEnabled` off is a registered client, so it keeps the default `true` - with the redirect URI rule gone, grant keys stop mirroring `redirectUri` into KV metadata, so a long redirect URI no longer pushes a grant over the 1,024-byte limit; the grant record and `listUserGrants()` still carry it ```ts // Default: a CIMD client's earlier grants are kept. await env.OAUTH_PROVIDER.completeAuthorization({ request, userId, scope, props, metadata }); // One grant per user and resource, for any client. For a CIMD client this signs out its other installations. await env.OAUTH_PROVIDER.completeAuthorization({ request, userId, scope, props, metadata, revokeExistingGrants: true }); ``` `npm run check` ran. I also ran cloudflare/mcp's CIMD tests against this build without the override from cloudflare/mcp#442: two sign-ins from one CIMD client keep both grants. --------- Co-authored-by: matthewhenry1 <31288868+matthewhenry1@users.noreply.github.com>
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.
Related: cloudflare/workers-oauth-provider#433 makes this the library default. This PR does not wait on it; remove this override once mcp.cloudflare.com upgrades to a release that includes it.
Stops one cause of
invalid_grant: Grant not foundon mcp.cloudflare.com: a new sign-in from a hosted CIMD client revokes the user's other connections from that client. Works with the current library (1.2.3) and needs no client change.Problem
invalid_grant: Grant not found, and reconnecting A breaks B. Only one connection per Cloudflare login survives.Change
revokeExistingGrants: falsefor CIMD clients (oauth-handler.ts#L380-L383), the workaround suggested in revokeExistingGrants default logs a user out of all their other devices when the client uses CIMD workers-oauth-provider#297.invalid_grant, are unchanged.Tradeoffs
refreshTokenTTLruns out or the client revokes them (RFC 7009).Testing
Library follow-up
clientIdMetadataDocumentFallback: false.