Skip to content

OAuth login loops after logout/restart: DCR placeholder token is treated as persisted token #305

Closed

Description

@AlexMKX

Summary

After logout -> restart -> login, OAuth for an HTTP upstream can enter a reconnect loop and never complete reliably. The loop is triggered by a persisted OAuth record that contains DCR client credentials but no real access token.

I can reproduce this consistently on Linux with mcpproxy v0.17.4.

Environment

  • mcpproxy: v0.17.4
  • OS: Linux
  • Upstream: HTTP OAuth server (gcw in my case)

Steps to Reproduce

  1. Start with a previously authenticated OAuth server.
  2. Call POST /api/v1/servers/<id>/logout.
  3. Call POST /api/v1/servers/<id>/restart.
  4. Call POST /api/v1/servers/<id>/login.
  5. Wait a few seconds.

Expected Behavior

  • One OAuth login flow starts.
  • User completes callback.
  • Connection retries once and becomes healthy.

Actual Behavior

  • Quick OAuth starts and returns auth URL.
  • Then the manager repeatedly logs:
    • Detected persisted OAuth token; triggering reconnect
    • with token_expires_at: 0001-01-01T00:00:00.000Z
  • Reconnect repeatedly starts new OAuth attempts.
  • Callback handling times out (OAuth authorization timeout).

Log Evidence

Observed sequence around 2026-02-15 08:55 (+03):

  • OAuth logout initiated
  • Successfully recreated server with fresh secrets
  • Starting quick OAuth flow
  • DCR succeeded
  • Authorization URL obtained
  • Waiting for OAuth callback in background
  • then repeated Detected persisted OAuth token; triggering reconnect with zero expiry.

Root Cause (code-level)

The reconnect monitor appears to treat a DCR-only placeholder record as a valid persisted token:

  1. DCR stores client credentials before token exchange, creating/updating a minimal OAuth record:
  • internal/upstream/core/connection_oauth.go (DCR success path, persists credentials)
  • internal/storage/bbolt.go UpdateOAuthClientCredentials(...) creates minimal record when none exists.
  1. PersistentTokenStore.GetToken() returns a token object from that record even when access token is empty / expiry is zero:
  • internal/oauth/persistent_token_store.go
  1. scanForNewTokens() reconnects when tok != nil (without validating token usability):
  • internal/upstream/manager.go (scanForNewTokens, reconnect branch)

This produces false positives and reconnect loops while quick OAuth callback is still pending.

Suggested Fix

In scanForNewTokens() only trigger reconnect when token is actually usable, e.g.:

  • tok.AccessToken != ""
  • and optionally not zero expiry (or valid refresh semantics)
  • and avoid reconnect while OAuth flow is currently in progress for that server.

Using a "valid persisted token" helper (instead of only tok != nil) would likely prevent this loop.

Related UX issue (possibly separate issue)

In daemon mode, mcpproxy auth login does not surface auth_url from /api/v1/servers/{id}/login because CLI client parses a legacy response shape in internal/cliclient/client.go.
If maintainers prefer, I can open this as a separate issue.

Activity

  1. tjsingleton commented on Feb 21, 2026

    @tjsingleton
    Contributor

    Love the PR description!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions