Record OAuth provenance and login identity for account tokens (#55397)

## Why

Token refresh needs the issuer and client ID used at login. Unverified token claims cannot establish that authority, and OAuth error bodies may echo credentials.

## What changed

- Save `oauth_provenance` and a new `login_owner_id` on browser and device-code login. Preserve the login identifier through token rotation.
- Refresh using the recorded issuer and client ID, retaining the existing endpoint override and fallback behavior for legacy records. Clear provenance when an override changes the endpoint or when a response without token rotation encounters a concurrently replaced refresh token.
- Keep both metadata fields optional for older records without inferring provenance from token claims.
- Remove backend token error details from structured logs and refresh error messages.
- Box large futures in token refresh, MCP initialization, and embedded app-server test startup to reduce surrounding async frame sizes.

## Testing

Add coverage for legacy record compatibility and metadata round trips, browser and device-code login persistence, refresh using recorded OAuth settings, metadata preservation through rotation, and provenance clearing for a superseded refresh token.

GitOrigin-RevId: b6b5d2fcbe2a284a171a242c1a17128af55f1024
This commit is contained in:
jif
2026-10-19 22:21:13 +00:00
committed by copyberry
parent e05028e7b0
commit 896604a12d
21 changed files with 219 additions and 74 deletions
+15
View File
@@ -21,9 +21,24 @@ pub struct TokenData {
pub refresh_token: String,
/// OAuth authority recorded when this refresh token was issued. Older records have no
/// provenance; never infer authority from unverified token claims.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub oauth_provenance: Option<AccountOAuthProvenance>,
/// Identifies one completed login; token rotation preserves it.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub login_owner_id: Option<String>,
pub account_id: Option<String>,
}
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq)]
pub struct AccountOAuthProvenance {
pub issuer: String,
pub client_id: String,
}
/// Flat subset of useful claims in id_token from auth.json.
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
pub struct IdTokenInfo {