Bind MCP OAuth refresh tokens to their issuer (#39615)

## Why

An authorization server discovered for an MCP server can change. A stored refresh token must not be sent to a different issuer than the one that originally granted it.

## What changed

- Persist the discovered authorization server issuer with new OAuth credentials and preserve it across refreshes.
- Validate that issuer against a single pinned metadata snapshot before refreshing or adopting stored refresh credentials.
- Require reauthentication when refresh credentials have no issuer or the issuer changed. An unexpired access token can still be used without exposing its refresh token.

## Testing

Add coverage for issuer persistence, missing and changed issuers, metadata changes during startup, and refresh-token preservation.

GitOrigin-RevId: 07e48ba892f627428a28bbed5cca4ad703e2a5fd
This commit is contained in:
Jeremy Rose authored and copyberry committed 2026-08-20 06:25:17 +00:00
1 parent 530c1aed58
commit 250b5ea2bf
16 files changed
+722 -110

No files matched your search

@@ -179,6 +179,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.header(CONTENT_TYPE, "application/json")
.body(Body::from(
serde_json::to_vec(&json!({
"issuer": format!("{metadata_base}/mcp"),
"authorization_endpoint": format!("{metadata_base}/oauth/authorize"),
"token_endpoint": format!("{metadata_base}/oauth/token"),
"scopes_supported": [""],