π The fast, Pythonic way to build MCP servers and clients.
fix: upstream token cache expires when refresh expires (#2410)
Sean McGrathf7c89e26308e
diff --git a/src/fastmcp/server/auth/oauth_proxy.py b/src/fastmcp/server/auth/oauth_proxy.pyindex 1998f4249..8cfa46d66 100644--- a/src/fastmcp/server/auth/oauth_proxy.py+++ b/src/fastmcp/server/auth/oauth_proxy.py@@ -1175,7 +1175,8 @@ class OAuthProxy(OAuthProvider):await self._upstream_token_store.put(key=upstream_token_id,value=upstream_token_set,- ttl=expires_in, # Auto-expire when access token expires+ ttl=refresh_expires_in+ or expires_in, # Auto-expire when refresh token, or access token expires)logger.debug("Stored encrypted upstream tokens (jti=%s)", access_jti[:8])@@ -1371,7 +1372,12 @@ class OAuthProxy(OAuthProvider):await self._upstream_token_store.put(key=upstream_token_set.upstream_token_id,value=upstream_token_set,- ttl=new_expires_in, # Auto-expire when refreshed access token expires+ ttl=new_refresh_expires_in+ or (+ int(upstream_token_set.refresh_token_expires_at - time.time())+ if upstream_token_set.refresh_token_expires_at+ else 60 * 60 * 24 * 30 # Default to 30 days if unknown+ ), # Auto-expire when refresh token expires)# Issue new minimal FastMCP access token (just a reference via JTI)