Repository navigation
Description
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:
- 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).
- 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.
- 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
oauth/broker: broaden id_token refresh gate from forward to broker mode
Merge pull request #122 from Altinity/oauth/forward-mode-id-token-ref…
oauth/forward: refresh near-expired upstream id_token at /token (Alti…