feat: per-server OAuth request settings for Google Chat sign-in #52

Merged
marti merged 4 commits from feature/google-chat-user-oauth into develop 2026-11-10 10:49:20 +01:00
Owner

Summary

Lets each user connect Google Chat with their own Google account, through the existing per_user upstream OAuth. Google has no dynamic registration, issues no refresh token by default, and does not document RFC 8707, so a remote server gets two new OAuth settings. Fixed scopes already worked; this adds a test that pins them.

 startUpstreamAuthorization
   auth(provider, { scope: adminScopes || challengeScope })
+    provider.validateResourceURL -> undefined   # only when sendResource is off
+  for each oauthAuthorizationParams: url.searchParams.set(name, value)
   insertFlow

 completeUpstreamAuthorization
   auth(provider, { authorizationCode })
+    provider.validateResourceURL -> undefined   # only when sendResource is off
   saveTokens({ resource })                      # undefined, so refresh omits it too
mcp_servers
  oauth_authorization_params  jsonb    default {}     # e.g. access_type=offline&prompt=consent
  oauth_send_resource         boolean  default true   # false: no resource in any OAuth request

An extra parameter cannot replace response_type, client_id, redirect_uri, state, code_challenge, code_challenge_method, scope or resource, so it cannot weaken state or PKCE. Rejected by the shared contract and flagged in the admin form.

Setup for Google Chat is in docs/deployment.md. The redirect URI is PUBLIC_URL/api/upstream-oauth/callback.

Evidence

  • Before: the 8 new cases in upstream-oauth.test.ts > authorization request settings fail (extra parameters not stored, resource still sent, reserved names accepted with 200).
    After: they pass, and so does the whole suite. npm test: 548 passed, 2 skipped. Typecheck and build pass; lint has one existing warning in a file this PR does not touch.
keeps the resource out of the authorization, the code exchange and the refresh
  authorization URL        has no resource
  token, authorization_code   has no resource
  token, refresh_token        has no resource
  • Real Google, up to the authorization URL (POST /api/admin/servers/:id/oauth/authorize against https://chatmcp.googleapis.com/mcp/v1, dummy client id): 200 with both settings. Discovery resolves to accounts.google.com.
sendResource=false  ...&scope=<the 3 chat scopes>&prompt=consent&access_type=offline
sendResource=true   ...&scope=<the 3 chat scopes>&resource=https://chatmcp.googleapis.com/mcp/v1&prompt=consent&access_type=offline

Not verified: a real sign-in, code exchange and refresh with a Google account, and therefore whether Google accepts resource. With a dummy client Google returns the same error with and without it, because it rejects the client first. The docs tell admins to turn the option off for Google, since its OAuth documentation does not list that parameter.

Merge Danger

Door: two-way

The migration only adds two columns with defaults, and earlier code ignores them. Migrations are forward only, so a rollback leaves the columns in place, unused.

Blast Radius: narrow

Existing servers keep today's behaviour through the defaults. Saving a change to either setting signs every user out of that server, as any OAuth settings change already does.

🤖 Generated with Claude Code

## Summary Lets each user connect Google Chat with their own Google account, through the existing `per_user` upstream OAuth. Google has no dynamic registration, issues no refresh token by default, and does not document RFC 8707, so a remote server gets two new OAuth settings. Fixed scopes already worked; this adds a test that pins them. ```diff startUpstreamAuthorization auth(provider, { scope: adminScopes || challengeScope }) + provider.validateResourceURL -> undefined # only when sendResource is off + for each oauthAuthorizationParams: url.searchParams.set(name, value) insertFlow completeUpstreamAuthorization auth(provider, { authorizationCode }) + provider.validateResourceURL -> undefined # only when sendResource is off saveTokens({ resource }) # undefined, so refresh omits it too ``` ```text mcp_servers oauth_authorization_params jsonb default {} # e.g. access_type=offline&prompt=consent oauth_send_resource boolean default true # false: no resource in any OAuth request ``` An extra parameter cannot replace `response_type`, `client_id`, `redirect_uri`, `state`, `code_challenge`, `code_challenge_method`, `scope` or `resource`, so it cannot weaken state or PKCE. Rejected by the shared contract and flagged in the admin form. Setup for Google Chat is in `docs/deployment.md`. The redirect URI is `PUBLIC_URL/api/upstream-oauth/callback`. ## Evidence - **Before:** the 8 new cases in `upstream-oauth.test.ts > authorization request settings` fail (extra parameters not stored, `resource` still sent, reserved names accepted with 200). **After:** they pass, and so does the whole suite. `npm test`: 548 passed, 2 skipped. Typecheck and build pass; lint has one existing warning in a file this PR does not touch. ```text keeps the resource out of the authorization, the code exchange and the refresh authorization URL has no resource token, authorization_code has no resource token, refresh_token has no resource ``` - **Real Google, up to the authorization URL** (`POST /api/admin/servers/:id/oauth/authorize` against `https://chatmcp.googleapis.com/mcp/v1`, dummy client id): 200 with both settings. Discovery resolves to `accounts.google.com`. ```text sendResource=false ...&scope=<the 3 chat scopes>&prompt=consent&access_type=offline sendResource=true ...&scope=<the 3 chat scopes>&resource=https://chatmcp.googleapis.com/mcp/v1&prompt=consent&access_type=offline ``` **Not verified:** a real sign-in, code exchange and refresh with a Google account, and therefore whether Google accepts `resource`. With a dummy client Google returns the same error with and without it, because it rejects the client first. The docs tell admins to turn the option off for Google, since its OAuth documentation does not list that parameter. ## Merge Danger **Door:** two-way The migration only adds two columns with defaults, and earlier code ignores them. Migrations are forward only, so a rollback leaves the columns in place, unused. **Blast Radius:** narrow Existing servers keep today's behaviour through the defaults. Saving a change to either setting signs every user out of that server, as any OAuth settings change already does. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Merge pull request 'develop' (#51) from develop into main
All checks were successful
CI / check (push) Successful in 5m51s
ffd2988285
Reviewed-on: #51
Google issues a refresh token only with access_type=offline and
prompt=consent, and has no dynamic registration or documented support for
RFC 8707. Extra parameters cannot replace the ones mcphub sets, so they
cannot weaken state or PKCE. Dropping resource applies to the authorization,
the code exchange and refresh alike.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs: describe the OAuth request settings and Google Chat setup
All checks were successful
CI / check (pull_request) Successful in 5m51s
ae311bbd36
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
marti merged commit 713ca48ecd into develop 2026-11-10 10:49:20 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
marti/mcphub!52
No description provided.