Skip to content

fix(auth): robustly enforce readonly scopes by injecting prompt=consent#504

Open
dumko2001 wants to merge 7 commits intogoogleworkspace:mainfrom
dumko2001:fix/issue-168-readonly-scope
Open

fix(auth): robustly enforce readonly scopes by injecting prompt=consent#504
dumko2001 wants to merge 7 commits intogoogleworkspace:mainfrom
dumko2001:fix/issue-168-readonly-scope

Conversation

@dumko2001
Copy link

Description

Robustly enforce readonly scopes by injecting prompt=consent into the OAuth flow when the --readonly flag is used. This ensures that Google always returns a refresh token and honors the requested readonly scopes, even if the user had previously authenticated with broader scopes.

The implementation:

  • Updates CliFlowDelegate to handle a force_consent flag.
  • Dynamically injects or modifies the prompt parameter in the OAuth URL to include consent, while preserving existing prompt values (e.g. select_account) using space-delimiting as per RFC 6749.
  • Passes the force_consent flag to the authenticator based on the presence of --readonly in the login arguments.

Fixes #168

Dry Run Output:
N/A (Authentication flow change)

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 15, 2026

🦋 Changeset detected

Latest commit: 937c6bf

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 an issue where readonly scopes might not be consistently enforced during the OAuth authentication process. By introducing a mechanism to explicitly inject prompt=consent into the OAuth URL when the --readonly flag is active, the system now guarantees that Google always returns a refresh token and respects the requested readonly permissions, thereby improving the reliability and security of authentication for readonly operations.

Highlights

  • Enforce Readonly Scopes: The OAuth flow now robustly enforces readonly scopes by injecting prompt=consent into the authorization URL when the --readonly flag is used. This ensures a refresh token is always returned and requested readonly scopes are honored, even if prior authentication had broader scopes.
  • CliFlowDelegate Update: The CliFlowDelegate struct was updated to include a force_consent flag, which controls the injection of the prompt=consent parameter.
  • Dynamic Prompt Injection: The InstalledFlowDelegate implementation now dynamically modifies or injects the prompt parameter in the OAuth URL to include consent, while carefully preserving any other existing prompt values (e.g., select_account) using space-delimiting.
  • Readonly Flag Detection: The handle_login function was updated to detect the presence of the --readonly command-line argument and pass this information as the force_consent flag to the authenticator.
Changelog
  • .changeset/fix-issue-168-readonly-scope.md
  • src/auth_commands.rs
    • Added a force_consent field to the CliFlowDelegate struct.
    • Modified the InstalledFlowDelegate::present_user_url method to dynamically inject prompt=consent into the OAuth URL if force_consent is true, handling existing prompt parameters gracefully.
    • Updated the handle_login function to detect the --readonly command-line argument.
    • Configured the CliFlowDelegate with the force_consent flag based on the detection of the --readonly argument during authenticator setup.
Activity
  • No specific activity (comments, reviews, or progress updates) has been recorded for this pull request yet.
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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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 robustly enforces readonly scopes by injecting prompt=consent into the OAuth flow. The changes are well-structured, adding a force_consent flag to CliFlowDelegate and dynamically modifying the OAuth URL. My main feedback is to improve the robustness of the check for an existing consent value in the prompt parameter to avoid potential issues with partial matches.

@dumko2001
Copy link
Author

Applied the suggested fix for robust prompt=consent injection. Now splitting by %20 and performing an exact match check, while also handling empty prompt parameters.

@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 implements the logic to enforce readonly scopes by injecting prompt=consent into the OAuth flow. The changes to pass the --readonly flag down to the CliFlowDelegate are well done.

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.

gws auth login --readonly + auth export --unmasked appears to allow full access on external machine

2 participants