Skip to content

forward mode: short-lived id_tokens cause early disconnect #121

Closed

Description

@BorisTyshkevich

Symptom

Forward-mode deployments (antalya-mcp confirmed; same applies to otel-google-mcp) issue session bearers that expire much sooner than the advertised 1h, sometimes within minutes.

Example from antalya pod log (2026-05-15):

```
19:30:38 INF upstream code exchange succeeded expires_in=3598 has_id_token=true
19:38:39 ERR OAuth token expired exp=1778872374
```

`exp=1778872374` = 2026-05-15 17:32:54 UTC. /token success was at 17:30:38 UTC. The Google id_token had ~2 minutes of remaining life when we forwarded it.

Why

In forward mode the bearer the MCP client receives is the Google id_token verbatim (oauth_server.go:1471). Google's id_token `exp` is set when Google originally minted the id_token, not at code-exchange time. On silent SSO over a warm Google session, the auth-code redemption returns a reused id_token whose remaining life can be anywhere from "full hour" to "about to expire". Result: the effective session window for the MCP client is `min(client idle, id_token remaining life at issuance)`, which is unpredictable.

`expires_in=3598` in the log is Google's access_token lifetime (unused — we forward the id_token, not the access_token).

Fix

Internally use Google's refresh_token grant at /token success to mint a fresh id_token before forwarding to the MCP client. Concretely:

  1. Set `oauth.upstream_offline_access: true` on forward-mode deployments so Google returns a refresh_token (incurs a one-time "have offline access" consent screen).
  2. In `handleOAuthTokenAuthCode`, after the upstream code exchange succeeds, if `tokenResp.RefreshToken != ""` AND the id_token's remaining life is below a threshold (proposed: 55 minutes), call Google's token endpoint with `grant_type=refresh_token` and use the resulting fresh id_token as the bearer.
  3. Discard Google's refresh_token after the call (v1 still doesn't issue downstream refresh — RFC: support CIMD inbound at /authorize #115 design unchanged).

Result: every /authorize round-trip yields a deterministic ~1h session window, end-to-end.

Scope

  • Forward mode only (antalya-mcp, otel-google-mcp). Gating-mode deployments don't forward the id_token; they derive identity at /token and issue their own bearer via Auth.Username. Unchanged.
  • Does NOT extend idle beyond Google's 1h id_token cap. To support longer idle would require reintroducing downstream refresh_token, which RFC: support CIMD inbound at /authorize #115 deliberately retired. Out of scope for this issue.

Non-goals

  • Downstream refresh_token reintroduction.
  • Replacing id_token-as-bearer with something MCP-minted (would require dropping CH-side <token_processor> validation against Google JWKS).

Detection

User-visible: ChatGPT/claude.ai shows "disconnected" within minutes of OAuth completion, even though we logged `expires_in=3598`.

Test plan

  • Unit test: /token path with id_token expiring in < 5 min → refresh path is taken, returned bearer has fresh exp.
  • Unit test: /token path with id_token expiring in > 55 min → refresh path is NOT taken (efficiency).
  • Unit test: `upstream_offline_access: false` → refresh path is never attempted regardless of id_token life.
  • E2E on antalya-mcp via claude.ai (forward mode + Google direct).

Activity

  1. added a commit that references this issue on May 16, 2026
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