Skip to content

fix(oauth): abort with oauth_client_id_required instead of empty-client_id authorize URL - #976

Merged
github-actions[bot] merged 4 commits into
mainfrom
fix/975-oauth-empty-client-id
Aug 13, 2026
Merged

github-actions[bot] merged 4 commits into
mainfrom
fix/975-oauth-empty-client-id

Conversation

@Dumbris

@Dumbris Dumbris commented Aug 13, 2026

Copy link
Copy Markdown
Member

Fixes #975.

Root cause

GitHub's authorization server (https://github.com/login/oauth) advertises no registration_endpoint in its RFC 8414 metadata, so Dynamic Client Registration is impossible. mcpproxy attempted DCR, got server does not support dynamic client registration from mcp-go, logged a warning, and fell through to "public client OAuth with PKCE, no client_id" — a premise that is incorrect (OAuth public clients still require a client_id; PKCE replaces the client secret, not the id). The result was https://github.com/login/oauth/authorize?client_id=&…, which GitHub 404s.

Two paths were affected:

  • getAuthorizationURLQuick (REST POST /api/v1/servers/{name}/login + mcpproxy auth login daemon mode) had no empty-client_id guard at all — the CLI printed "OAuth authentication flow initiated successfully" and exited 0 on a guaranteed-broken URL.
  • handleOAuthAuthorization (connection-triggered) had a guard, but only keyed on DCR errors containing "403" (the Figma case) and misreported every failure as "DCR returned 403".

Fix

New Client.emptyClientIDFlowError guard, wired into both paths: parses the final authorization URL (after oauth.extra_params injection, so a client_id supplied that way still passes) and returns a structured oauth_client_id_required / OAUTH_NO_CLIENT_ID error with an actionable suggestion instead of ever surfacing a broken URL.

Verification (isolated instance against real api.githubcopilot.com)

  • Before (main @ 2b90a10, reproduced live): REST login → HTTP 200 success:true with auth_url=…client_id=&…; CLI → exit 0 "flow initiated successfully".
  • After: REST login → success:false, error_type=oauth_client_id_required with suggestion to set oauth.client_id; CLI → exit 1 with the full structured error block; zero authorize URLs in logs.
  • Regression guard: with "oauth": {"client_id": "…"} configured, the login flow still returns a working authorize URL carrying that client_id.
  • go test -race ./internal/upstream/... ./internal/oauth/... green; both editions build; golangci-lint (CI v2 config) 0 issues; 5 new unit tests for the guard.

…mpty-client_id authorize URL (#975)

When a provider lacks a Dynamic Client Registration endpoint (GitHub's
https://github.com/login/oauth advertises none), mcpproxy swallowed the DCR
failure and proceeded as a 'public client without client_id', producing
https://github.com/login/oauth/authorize?client_id=&... which GitHub 404s.
OAuth public clients (RFC 8252 + PKCE) still require a client_id — PKCE
replaces the client secret, not the id.

- New Client.emptyClientIDFlowError guard: parses the final authorization URL
  (after oauth.extra_params injection) and returns a structured
  oauth_client_id_required / OAUTH_NO_CLIENT_ID contracts.OAuthFlowError with
  an actionable suggestion when client_id is empty or absent.
- Wired into getAuthorizationURLQuick (REST POST /servers/{name}/login and
  'mcpproxy auth login' daemon path) which previously had no guard — the CLI
  used to print 'OAuth flow initiated successfully' and exit 0 on a broken URL;
  it now exits 1 with the structured error.
- Replaces the connection path's 403-only inline check (Figma case), which
  misreported every DCR failure as 'returned 403'; the guard is now
  unconditional on the final URL in both paths.

Verified live against api.githubcopilot.com on an isolated instance: REST login
returns the structured error (no auth_url), CLI exits 1 with suggestion, and a
configured oauth.client_id still produces a working authorize URL.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

@codecov-commenter

codecov-commenter commented Aug 13, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 72.09302% with 12 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/upstream/core/connection_oauth.go 72.09% 12 Missing ⚠️

📢 Thoughts on this report? Let us know!

… in error details

Codex cross-review round 1 findings, both verified genuine:

- handleOAuthAuthorizationWithResult (ForceOAuthFlowWithResult / manual CLI
  flows) still built, stored, and opened an empty-client_id authorize URL when
  DCR failed with anything other than a 403. Same guard now applied after
  extra-param injection, before the URL is stored or the browser opened.
- The unified error previously discarded the actual DCR result (the old
  connection-path shape hardcoded 403/Forbidden for every failure, and the
  replacement dropped it entirely). emptyClientIDFlowError now takes the DCR
  error: details.dcr_status carries the real error text, with status_code=403
  preserved when the failure was an actual 403 — a Figma-style rejection stays
  distinguishable from a GitHub-style missing registration endpoint.
- All three 403-only early returns removed; every path now produces one
  consistent oauth_client_id_required shape via the final-URL guard.

3 new unit tests (403 details, unsupported details, no-DCR-attempt); verified
live: REST login now returns dcr_status.error='server does not support dynamic
client registration', zero authorize URLs in logs.
…-effort 403 detection

Codex cross-review round 2, both verified:

- A client_id injected only via oauth.extra_params passes the URL guard but is
  never sent by the handler at token exchange (mcp-go has no SetClientID), so
  it only works against lenient providers. Keep the escape hatch (pre-existing
  behavior) but WARN with a pointer to oauth.client_id so the post-callback
  failure is diagnosable. Guard now takes the handler via a clientIDProvider
  interface.
- DCRStatus.StatusCode: also map 'Forbidden' to 403; documented as best-effort
  since mcp-go registration errors are untyped (a 403 with a valid OAuth JSON
  body surfaces without any status text) — the verbatim error string remains
  the authoritative detail.

2 new unit tests (10 total).
Codex round 3 (verified): OAuthTransportWrapper injects every oauth.extra_params
entry — client_id included — into token request bodies, so an extra_params
client_id DOES reach token exchange and the round-2 warning would have
misdiagnosed working configurations. Warning and the clientIDProvider plumbing
removed; the guard comment now documents why extra_params client_id pass-through
is fully functional.
@github-actions

github-actions Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

📦 Build Artifacts

Workflow Run: View Run
Branch: fix/975-oauth-empty-client-id

Available Artifacts

  • archive-darwin-amd64 (28 MB)
  • archive-darwin-arm64 (26 MB)
  • archive-linux-amd64 (17 MB)
  • archive-linux-arm64 (15 MB)
  • archive-windows-amd64 (28 MB)
  • archive-windows-arm64 (25 MB)
  • frontend-dist-pr (0 MB)
  • installer-dmg-darwin-amd64 (22 MB)
  • installer-dmg-darwin-arm64 (20 MB)

How to Download

Option 1: GitHub Web UI (easiest)

  1. Go to the workflow run page linked above
  2. Scroll to the bottom "Artifacts" section
  3. Click on the artifact you want to download

Option 2: GitHub CLI

gh run download 31682945858 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QA verified live (issue #975 repro + fix acceptance); Codex cross-review CLEAN after 4 rounds; qa-gate success at this SHA

@github-actions
github-actions Bot merged commit 9d031c0 into main Aug 13, 2026
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GitHub MCP OAuth DCR opens authorization URL with empty client_id

2 participants