Skip to content

fix(gmail): use OAuth userinfo endpoint for From display name fallback#684

Open
malob wants to merge 1 commit intogoogleworkspace:mainfrom
malob:fix/display-name-fallback
Open

fix(gmail): use OAuth userinfo endpoint for From display name fallback#684
malob wants to merge 1 commit intogoogleworkspace:mainfrom
malob:fix/display-name-fallback

Conversation

@malob
Copy link
Copy Markdown
Contributor

@malob malob commented Apr 7, 2026

Description

Fixes the From display name fallback for Workspace accounts where the sendAs identity has no display name configured. The previous fallback called the People API (people.googleapis.com/v1/people/me), which requires the People API to be separately enabled in the GCP project. When it isn't enabled, the 403 accessNotConfigured error was misreported as "grant the profile scope" — even when the userinfo.profile scope was already present in the token.

Root cause

The People API has two prerequisites: the OAuth scope (userinfo.profile) AND the API enabled in the GCP project console. The error handler at the old fetch_profile_display_name only checked for 403 and assumed it meant "missing scope," which is wrong when the scope is granted but the API isn't enabled.

The fix

Switch the fallback from the People API to the OAuth userinfo endpoint (oauth2/v2/userinfo). This endpoint:

  • Only requires the userinfo.profile scope (no separately-enabled API)
  • Returns {"name": "...", ...} at the top level (simpler response shape)
  • Is the same endpoint the CLI already uses for email lookup after login (auth_commands.rs)

Other improvements

  • Diagnostic for empty display name: When the userinfo endpoint succeeds but returns no name field (e.g. a freshly-provisioned account with no profile configured), a note is now printed to stderr. Previously this was completely silent — the user got no display name with no explanation.
  • Context-appropriate tips: GOOGLE_WORKSPACE_CLI_TOKEN users now see a tip about setting a token with the profile scope, instead of being told to run gws auth login (which doesn't apply to them).
  • Function renames: fetch_profile_display_namefetch_userinfo_display_name, parse_profile_display_nameparse_userinfo_display_name to reflect the new endpoint.

What this does NOT change

The primary display name path (sendAs identity lookup via /users/me/settings/sendAs) is untouched. This fix only affects the fallback for Workspace accounts where sendAs returns an empty displayName. The token cache and auth flow are also unchanged.

Verified

  • Built the fixed binary and created a draft via +send --draft — From header correctly shows display name, no spurious tip printed.
  • 703 tests pass, clippy clean.

Fixes #644

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.

The People API fallback for resolving the From display name on Workspace
accounts required people.googleapis.com to be enabled in the GCP
project. When disabled, the 403 was misreported as "grant profile scope"
even when the scope was already present (googleworkspace#644).

Switch to the OAuth userinfo endpoint (oauth2/v2/userinfo), which only
requires the userinfo.profile scope and no separately-enabled API.
Log a note when the endpoint succeeds but returns no display name,
making the silent degradation visible. Give GOOGLE_WORKSPACE_CLI_TOKEN
users a context-appropriate tip instead of telling them to run
gws auth login.

Fixes googleworkspace#644
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 7, 2026

🦋 Changeset detected

Latest commit: dbba810

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

@googleworkspace-bot googleworkspace-bot added area: auth area: core Core CLI parsing, commands, error handling, utilities labels Apr 7, 2026
@gemini-code-assist
Copy link
Copy Markdown
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 the Gmail display name fallback mechanism failed for Workspace accounts due to an unnecessary dependency on the People API. By switching to the standard OAuth userinfo endpoint, the CLI now correctly handles display name resolution without requiring additional API enablement in the GCP project. The changes also improve error reporting and user guidance for authentication scopes.

Highlights

  • API Migration: Replaced the People API with the OAuth userinfo endpoint for fetching display names, removing the requirement to enable the People API in the GCP project.
  • Improved Diagnostics: Added explicit feedback when the userinfo endpoint returns no display name and provided context-aware tips for users utilizing environment-based tokens.
  • Code Refactoring: Renamed internal functions and updated tests to align with the new userinfo-based implementation.
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
Copy Markdown
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 replaces the Google People API with the OAuth userinfo endpoint for retrieving Gmail sender display-name fallbacks, removing the requirement to enable the People API in GCP projects. It introduces context-aware tips for users based on whether they are using environment-based tokens or saved credentials and updates the internal fetching and parsing logic accordingly. I have no feedback to provide.

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

Labels

area: auth area: core Core CLI parsing, commands, error handling, utilities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gmail +send shows "grant profile scope" tip and sends with null From name even when profile scope is granted

2 participants