Skip to content

fix(oauth): support OAuth sign-in from a remote Web UI - #1597

Merged
Dumbris merged 4 commits into
smart-mcp-proxy:mainfrom
tomgrin10:fix/remote-web-oauth
Oct 13, 2026
Merged

Dumbris merged 4 commits into
smart-mcp-proxy:mainfrom
tomgrin10:fix/remote-web-oauth

Conversation

@tomgrin10

@tomgrin10 tomgrin10 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes #1595. On a headless host, the Web UI discarded the authorization URL and said “Check your browser.” Following the URL manually then sent the callback to localhost on the user's laptop.

Open the returned authorization URL in a tab reserved during the user's click. Blocked popups get a persistent sign-in link; unsafe URL schemes are rejected and the tab has no opener.

Opt into a remote callback with an explicit HTTPS origin:

"oauth": { "callback_base_url": "https://proxy.example.ts.net:8447" }

The reverse proxy must forward /oauth/callback/<server-name> to MCPProxy's main HTTP listener. This reuses PKCE and atomic, single-use state dispatch, rejecting missing, duplicate, expired, replayed and cross-server states. Invalid public callbacks do not alter upstream health. Responses disable caching/referrer disclosure; no API key is sent to the provider, and the origin is never inferred from request headers. Loopback remains the default.

DCR registrations follow the exact external redirect URI and survive changes to an unpinned private callback port. Configuration merge, validation, reconnect detection, persistence, docs and generated OpenAPI include the new setting. Static clients must register the exact HTTPS callback with a provider that permits it.

Manual account-switching/recovery controls are independent in #1599, tracked in #1598. This PR contains only the remote-browser flow.

Testing

  • I have tested these changes locally

  • I have added/updated tests that prove my fix is effective or my feature works

  • All existing tests pass

  • go test -p 2 ./internal/config ./internal/oauth ./internal/upstream/core passed.

  • Focused race tests passed for callback state routing, HTTPS PKCE, DCR migration, private-port changes, origin validation and redirect persistence.

  • Five focused server smoke/OAuth tests passed with MCPPROXY_BINARY_PATH set to a binary built from this independent branch.

  • Nine affected frontend tests and npm run build (including TypeScript checking) passed. The full frontend suite previously passed on the remote-login implementation: 2,601 tests.

  • Playwright drove the branch's embedded UI through a local HTTPS reverse proxy with a test provider: new browser tab → consent → HTTPS callback → PKCE token exchange → authenticated tool reads, with desktop and mobile checks.

  • OpenAPI regeneration and git diff --check passed.

Test Files  2 passed (2)
Tests       9 passed (9)
{"browser_login":"passed","pkce_exchanges":1,"authenticated_tool_reads":2}

The complete server suite is not claimed: its initial broad run lacked the required binary-path setting and exceeded the default ten-minute deadline. Relevant server tests were rerun successfully with that setting.

The two independent PR branches also merge without conflicts; their combined 14 affected frontend tests and production build pass.

@tomgrin10
tomgrin10 force-pushed the fix/remote-web-oauth branch from 267bbf4 to cec2953 Compare October 12, 2026 09:13
@werty1st

Copy link
Copy Markdown

I was just going to let claude build the same. i can confirm it works with the gitlab mcp.

    {
      "quarantined": false,
      "name": "GitLab",
      "url": "https://gitlab.domain.de/api/v4/mcp",
      "protocol": "http",
      "oauth": {
        "callback_base_url": "https://mcpproxy.homelab.de"
      },
      "enabled": true
    }

Dumbris and others added 3 commits October 13, 2026 10:03
…s browser is not the user's

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…gistered; tighten callback_base_url validation

A login completed through oauth.callback_base_url stored the private loopback
URI with its token, so the next connect saw a mismatch and cleared a valid DCR
registration after every sign-in (cross-model review finding). Also reject
out-of-range ports and malformed IPv6 literals in callback_base_url, refuse the
"."/".." server names the mux would normalise away, and make a remote UI
treat a daemon-host browser launch with no auth_url as an error instead of a
success toast.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@Dumbris Dumbris changed the title Support OAuth sign-in from a remote Web UI fix(oauth): support OAuth sign-in from a remote Web UI Oct 13, 2026
@Dumbris

Dumbris commented Oct 13, 2026

Copy link
Copy Markdown
Member

Thank you @tomgrin10 — this is a genuinely good piece of work: the public callback is gated on an explicitly configured origin, the single-use state dispatch is reused instead of re-implemented, unknown-state hits don't poison upstream health, and the DCR invalidation cases are thought through. The docs and the test provider coverage made it easy to verify.

What I did before merging:

  • Read the Go and frontend diffs, built both editions, ran -race on internal/config, internal/oauth, internal/upstream/core, both golangci-lint configs, the full frontend unit suite (2652 tests) and npm run build.
  • Live check on a scratch core with the repo's test OAuth provider: /oauth/callback/<name> on the main listener answers 400 for the configured server, 404 for unconfigured ones, 405 on POST, with the REST API still 401 without a key; the auth URL carries the HTTPS redirect; a bogus callback left health untouched; a full sign-in completed through the Web UI.
  • Independent cross-model review (opencode, gpt-6.1-sol) on the backend and frontend halves.

Three things I pushed to your branch (hope that's OK — "allow edits by maintainers" was on):

  1. Duplicate sign-in tab on local installs. openOAuthLogin always navigated the reserved popup when an auth_url came back, but the daemon also opens its host browser when it isn't headless, so the common localhost case got the provider page twice. Now the popup is reserved only when the UI is served from a non-loopback host (uiIsRemote); a local UI leaves the daemon's launch alone and only opens a tab itself when browser_opened is false (HEADLESS, Docker, no xdg-open), falling back to the persistent toast link. The remote path is unchanged.
  2. Remote logins lost their DCR registration on every reconnect (found by the cross-model review, confirmed with a failing test). exchangeAuthorizationCode persisted cb.RedirectURI (the loopback listener) with the token, so the next createOAuthConfigInternal saw a stored URI ≠ the HTTPS one and cleared a valid registration. Now it persists cb.EffectiveRedirectURI(); TestLoginCompletion_RemoteCallbackPersistsEffectiveRedirectURI pins it (and fails without the one-line fix).
  3. Small validation tightening: callback_base_url rejects out-of-range ports and malformed IPv6 literals; the ./.. server names the mux would normalise away are refused for remote callbacks; a remote UI treats "daemon opened its own browser, no URL" as an error rather than a success toast. Plus a merge of main with oas/docs.go regenerated, and the conventional-commit title our check requires.

Merging once CI is green. Thanks again — this unblocks headless/Tailscale users properly.

@Dumbris
Dumbris merged commit 0aff450 into smart-mcp-proxy:main Oct 13, 2026
47 checks passed
@codecov-commenter

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 84.69388% with 15 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/config/oauth_remote_callback.go 70.00% 3 Missing and 3 partials ⚠️
internal/oauth/config.go 72.22% 2 Missing and 3 partials ⚠️
internal/oauth/remote_callback.go 90.47% 3 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

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.

Web UI OAuth login cannot complete from a remote headless host

4 participants