Skip to content

gsearch-cli v0.2.1

Latest

Choose a tag to compare

@aeroxy aeroxy released this 27 Jun 07:14

1. High-Level Summary (TL;DR)

  • Impact: Medium - Fixes OAuth token refresh failures and enables proxy support.
  • Key Changes:
    • Makes refresh_token optional in the API response to align with Google's OAuth behavior.
    • Preserves the existing refresh_token during 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.

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:#1a5e20

3. Detailed Change Analysis

Auth Module (src/auth.rs)

  • What Changed:
    • Token Deserialization: Modified the TokenResponse struct to make refresh_token an Option<String>. Google's refresh-token grant only returns the refresh token during the initial authorization_code exchange, causing deserialization errors during subsequent refreshes if expected as a strict String.
    • Token Refresh Logic: Updated the refresh logic to retain the old refresh_token by using .unwrap_or_else(|| auth.refresh_token.clone()) when a new one is absent.
    • Login Logic: Enforced the presence of a refresh_token during the initial login phase using .context().
    • Proxy Support: Removed .no_proxy() from the reqwest::ClientBuilder in both the login and refresh methods, allowing the client to respect proxy configurations (e.g., HTTPS_PROXY).

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 AntigravityAuth still stores refresh_token as a String.