Repository navigation
1. High-Level Summary (TL;DR)
- Impact: Medium - Fixes OAuth token refresh failures and enables proxy support.
- Key Changes:
- Makes
refresh_tokenoptional in the API response to align with Google's OAuth behavior. - Preserves the existing
refresh_tokenduring token refresh if the API response omits it. - Removes
.no_proxy()from the HTTP client builder, allowing traffic to correctly route through configured system proxies. - Adds better error context during JSON parsing and initial login token extraction.
- Makes
2. Visual Overview (Code & Logic Map)
graph TD
subgraph "src/auth.rs"
TR["TokenResponse struct"]
TM_Refresh["TokenManager::refresh_token()"]
TM_Login["TokenManager::login()"]
end
TR -->|"refresh_token: Option<String>"| TM_Refresh
TR -->|"refresh_token: Option<String>"| TM_Login
TM_Refresh -->|"unwrap_or_else(|| auth.refresh_token)"| Auth_Refresh["AntigravityAuth (Refreshed)"]
TM_Login -->|"context('missing refresh_token')?"| Auth_New["AntigravityAuth (New Login)"]
style TR fill:#fff3e0,color:#e65100
style TM_Refresh fill:#bbdefb,color:#0d47a1
style TM_Login fill:#bbdefb,color:#0d47a1
style Auth_Refresh fill:#c8e6c9,color:#1a5e20
style Auth_New fill:#c8e6c9,color:#1a5e203. Detailed Change Analysis
Auth Module (src/auth.rs)
- What Changed:
- Token Deserialization: Modified the
TokenResponsestruct to makerefresh_tokenanOption<String>. Google's refresh-token grant only returns the refresh token during the initialauthorization_codeexchange, causing deserialization errors during subsequent refreshes if expected as a strictString. - Token Refresh Logic: Updated the refresh logic to retain the old
refresh_tokenby using.unwrap_or_else(|| auth.refresh_token.clone())when a new one is absent. - Login Logic: Enforced the presence of a
refresh_tokenduring the initial login phase using.context(). - Proxy Support: Removed
.no_proxy()from thereqwest::ClientBuilderin both the login and refresh methods, allowing the client to respect proxy configurations (e.g.,HTTPS_PROXY).
- Token Deserialization: Modified the
API Response Changes (TokenResponse)
| Param | Old Type | New Type | Description |
|---|---|---|---|
refresh_token |
String |
Option<String> |
Made optional because Google OAuth refresh grants omit it. |
Error Handling Enhancements
| Original Code | New Code | Reason |
|---|---|---|
res.json().await? |
res.json().await.context("parse refresh token response")? |
Improves debugging visibility if Google's token endpoint changes structure. |
4. Impact & Risk Assessment
- Breaking Changes: None. The local configuration and state structures remain backward-compatible since
AntigravityAuthstill storesrefresh_tokenas aString.