Skip to content

feat: add HTTP proxy support via environment variables#622

Open
femto wants to merge 4 commits intogoogleworkspace:mainfrom
femto:feat/proxy-support-rebased
Open

feat: add HTTP proxy support via environment variables#622
femto wants to merge 4 commits intogoogleworkspace:mainfrom
femto:feat/proxy-support-rebased

Conversation

@femto
Copy link

@femto femto commented Mar 25, 2026

Summary

When http_proxy/https_proxy/all_proxy environment variables are set, use reqwest (which supports proxy env vars natively) for token refresh and the auth login token exchange instead of relying only on yup-oauth2's hyper-based client.

This enables gws to work in environments that require an HTTP proxy to access Google APIs.

Supersedes closed PR #423 after rebasing onto the cargo workspace refactor.

Changes

  • crates/google-workspace-cli/src/auth.rs
    • Add shared proxy env detection
    • Add proxy-aware token refresh via reqwest
    • Improve error-body handling for failed token refresh responses
  • crates/google-workspace-cli/src/auth_commands.rs
    • Add proxy-aware OAuth login flow for auth code exchange
    • Extract the non-proxy yup-oauth flow into a helper for readability
    • Reuse shared proxy/error helpers and keep the newer workspace auth scope behavior intact
  • crates/google-workspace-cli/Cargo.toml
    • Keep reqwest configured with SOCKS support in the workspace crate
  • .changeset/proxy-support-review-fixes.md
    • Include a patch changeset for the CLI package

Testing

  • cargo clippy -p google-workspace-cli -- -D warnings
  • cargo test -p google-workspace-cli auth::tests::
  • cargo test -p google-workspace-cli auth_commands::tests::

femto added 3 commits March 25, 2026 12:10
When http_proxy/https_proxy/all_proxy environment variables are set,
use reqwest (which natively supports proxy) for token refresh instead
of yup-oauth2's hyper-based client (which doesn't support proxy).

This enables gws to work in environments that require HTTP proxy to
access Google APIs (e.g., users in China).

Changes:
- Cargo.toml: Enable reqwest's default features including proxy support
- src/auth.rs: Add proxy-aware token refresh using reqwest as fallback

Fixes googleworkspace#422
When proxy env vars are set, use a custom OAuth flow with reqwest
for token exchange instead of yup-oauth2's hyper-based client.

Changes to auth_commands.rs:
- Add login_with_proxy_support() for proxy-aware OAuth login
- Add exchange_code_with_reqwest() for token exchange via reqwest
- Detect proxy env vars and choose appropriate flow
@changeset-bot
Copy link

changeset-bot bot commented Mar 25, 2026

🦋 Changeset detected

Latest commit: ec20bdf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@googleworkspace/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the gws command-line interface by integrating robust HTTP proxy support. It allows the CLI to seamlessly authenticate and interact with Google APIs in network environments that mandate the use of an HTTP proxy. The changes involve a strategic use of the reqwest library for proxy-aware token management and OAuth flows, ensuring that the tool remains functional and reliable across diverse network configurations.

Highlights

  • HTTP Proxy Support: Implemented support for http_proxy, https_proxy, and all_proxy environment variables, enabling the gws CLI to function in proxy-restricted environments.
  • Conditional Client Usage: The CLI now dynamically switches between reqwest (which natively supports proxy environment variables) and yup-oauth2 for token operations. reqwest is used when proxy environment variables are detected, otherwise yup-oauth2 is used for its speed and caching.
  • Proxy-Aware Token Refresh: The access token refresh mechanism was updated to use reqwest when a proxy is configured, ensuring successful token acquisition through the proxy.
  • Proxy-Aware OAuth Login Flow: The OAuth login process for exchanging authorization codes for tokens has been refactored to use reqwest when proxy environment variables are present, facilitating authentication in proxy environments.
  • Improved Error Handling: Enhanced error reporting for failed token refresh responses by including the response body, providing more diagnostic information.
  • SOCKS Proxy Feature: The reqwest dependency was updated to include the socks feature, adding support for SOCKS proxies.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Generative AI Prohibited Use Policy, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces proxy support for OAuth authentication flows in the Google Workspace CLI. This is achieved by adding the socks feature to the reqwest dependency and implementing new functions that leverage reqwest for proxy-aware token refreshing and authorization code exchange. The existing authentication logic has been updated to conditionally use these new proxy-aware flows when proxy environment variables are detected. Unit tests for the new proxy-related utilities have also been added. The review comments suggest that creating a new reqwest::Client for each function call is inefficient and recommend using a single, shared client instance across the application to improve performance.

@femto
Copy link
Author

femto commented Mar 25, 2026

Addressed the reqwest client reuse feedback by adding a shared client helper backed by std::sync::OnceLock in crates/google-workspace/src/client.rs and switching the proxy auth flows to use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant