Skip to content

fix(auth): report token info in status when using GOOGLE_WORKSPACE_CLI_TOKEN#546

Open
dumko2001 wants to merge 6 commits intogoogleworkspace:mainfrom
dumko2001:fix/auth-status-token-v2
Open

fix(auth): report token info in status when using GOOGLE_WORKSPACE_CLI_TOKEN#546
dumko2001 wants to merge 6 commits intogoogleworkspace:mainfrom
dumko2001:fix/auth-status-token-v2

Conversation

@dumko2001
Copy link
Contributor

@dumko2001 dumko2001 commented Mar 18, 2026

Description

Ensure that gws auth status correctly reports the validity, user, and scopes of an access token provided via the GOOGLE_WORKSPACE_CLI_TOKEN environment variable. Previously, the status command only checked stored credentials, which could be confusing when using direct token injection.

Checklist:

  • My code follows the AGENTS.md guidelines (no generated google-* crates).
  • I have run cargo fmt --all to format the code perfectly.
  • I have run cargo clippy -- -D warnings and resolved all warnings.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have provided a Changeset file (e.g. via pnpx changeset) to document my changes.

@changeset-bot
Copy link

changeset-bot bot commented Mar 18, 2026

🦋 Changeset detected

Latest commit: 4101d3f

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

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 addresses a previous limitation in the gws auth status command where it failed to provide comprehensive information for access tokens supplied directly through an environment variable. The update ensures that the command now accurately displays the token's validity, associated user, and granted scopes, thereby improving clarity and consistency for users who manage authentication via GOOGLE_WORKSPACE_CLI_TOKEN.

Highlights

  • Enhanced gws auth status command: The gws auth status command now correctly reports the validity, user, and scopes of an access token when it is provided via the GOOGLE_WORKSPACE_CLI_TOKEN environment variable.
  • Direct Token Handling: Introduced logic to prioritize and process access tokens directly from the GOOGLE_WORKSPACE_CLI_TOKEN environment variable before falling back to stored credentials.
  • Unified Token Information Retrieval: Refactored the token information retrieval process to use a single path for fetching user details and scopes, whether the token comes from stored credentials or the environment variable.
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 correctly adds support for GOOGLE_WORKSPACE_CLI_TOKEN in the gws auth status command. However, the refactoring has introduced a regression where error reporting for failed token refreshes (e.g., due to an expired refresh token) is lost. My review includes a suggestion to restore this important feedback for the user.

@googleworkspace-bot
Copy link
Collaborator

/gemini review

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 enhances the authentication status command by allowing it to use an access token provided directly via the GOOGLE_WORKSPACE_CLI_TOKEN environment variable. The handle_status function in src/auth_commands.rs was modified to prioritize this environment variable for obtaining an access token. If the environment variable is not set, the existing logic for loading credentials and exchanging a refresh token is used. Subsequently, the retrieved access token (from either source) is used to fetch user information and granted scopes from Google APIs, improving clarity in the reported authentication status.

@googleworkspace-bot
Copy link
Collaborator

/gemini review

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 the ability for the gws auth status command to report token information when an access token is provided via the GOOGLE_WORKSPACE_CLI_TOKEN environment variable, in addition to existing credential store methods. However, a regression was introduced where the error reporting for failed refresh token exchanges was removed. Previously, the system would capture and display error_description and set token_valid: false, but now, if the exchange fails, the access_token is simply None, leading to silent failures and potentially confusing user output.

@dumko2001
Copy link
Contributor Author

Restored the error reporting for failed token refresh in gws auth status. If the refresh token exchange fails, the command now correctly reports token_valid: false and populates token_error with the description from Google's response, resolving the regression identified in review.

@googleworkspace-bot
Copy link
Collaborator

/gemini review

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 correctly adds support for GOOGLE_WORKSPACE_CLI_TOKEN to the auth status command and refactors the logic to handle both direct tokens and tokens from credentials. My review includes two high-severity suggestions: one to improve performance by reusing the reqwest::Client instance, and another to improve correctness by properly URL-encoding the access token in the tokeninfo request.

@dumko2001
Copy link
Contributor Author

Refactored handle_status to reuse a single reqwest::Client instance for all requests within the block and updated the tokeninfo call to use .query() for proper URL-encoding of the access token, as suggested in review.

@googleworkspace-bot
Copy link
Collaborator

/gemini review

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 correctly adds support for GOOGLE_WORKSPACE_CLI_TOKEN in the gws auth status command, allowing it to report token information when this environment variable is used. The implementation is functional, but I've identified a significant maintainability issue in src/auth_commands.rs where the logic for retrieving the access token has become overly complex and includes side effects within a let binding. I've left a comment with a recommendation to refactor this for better clarity and separation of concerns.

@dumko2001 dumko2001 force-pushed the fix/auth-status-token-v2 branch from 960d2b9 to 07beab6 Compare March 18, 2026 11:05
@dumko2001
Copy link
Contributor Author

Refactored the access token retrieval logic into a separate get_status_access_token helper function. This addresses the maintainability concerns raised in review by simplifying the main handle_status logic and ensuring side effects are handled cleanly.

@googleworkspace-bot
Copy link
Collaborator

/gemini review

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 correctly adds support for GOOGLE_WORKSPACE_CLI_TOKEN to the auth status command by refactoring the token acquisition logic. My review identifies two high-severity issues: a performance regression due to using synchronous file I/O in an async context, and a bug where a JSON parsing error is not handled, leading to silent failure. Code suggestions are provided for both issues.

…ccess_token

- Use tokio::fs::read_to_string instead of blocking std::fs::read_to_string
- Add match arm to handle resp.json() failures with error message
- Aligns with repo patterns for async I/O
@googleworkspace-bot
Copy link
Collaborator

/gemini review

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

The pull request effectively addresses the issue of reporting token information in gws auth status when using GOOGLE_WORKSPACE_CLI_TOKEN. The introduction of the get_status_access_token helper function centralizes token retrieval logic, improving code organization and readability. Error handling for network requests and JSON parsing within this new function is robust, ensuring that the output object accurately reflects the token's validity and any associated errors. The integration into handle_status is clean and correctly leverages the new abstraction. Overall, this is a well-implemented and maintainable change.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants