gmail +read returns 403 quota-project error when authenticated with default scopes

Open
#843 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

  • #939 by @mittalpk — closed without merging

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
75/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
rust

Research direction

Start in the +read helper at fetch_message_metadata and trace its use of crate::client::build_client() and send_with_retry, comparing it with executor.rs and auth::get_quota_project(). Verify the reproduction commands, then confirm that +read supplies the quota project header and succeeds with default scopes without breaking the documented non-project-member case.

Written by the indexing model from the issue text.

Description

gws gmail +read fails with:

Your application is authenticating by using local Application Default Credentials.
The gmail.googleapis.com API requires a quota project, which is not set by default.

The equivalent raw command succeeds:

gws gmail users messages get --params '{"userId":"me","id":"<id>","format":"full"}'

Cause

Google identifies tokens from the Cloud SDK client (764086051850-...) as ADC and requires the x-goog-user-project header. Standard resource commands go through executor.rs, which calls auth::get_quota_project() and adds the header. The +read helper bypasses executor.rs and calls fetch_message_metadata directly via crate::client::build_client() and send_with_retry. The request goes out with .bearer_auth(token) only, no quota project header.

This gap exists because #242 moved the x-goog-user-project injection from build_client() into executor.rs. When +read was added in #526, it called build_client() directly and missed the header.

Reproduction

gws auth login   # default scopes (gmail.modify)
gws gmail +read --id <any-message-id>
# -> 403 accessNotConfigured
gws gmail users messages get --params '{"userId":"me","id":"<id>","format":"full"}'
# -> succeeds

Adding gmail.readonly to the token does not help — the scope is irrelevant. The missing header is the sole cause.

Related

  • #242 — moved x-goog-user-project from build_client() to executor.rs
  • #526 — introduced +read bypassing executor.rs
  • #729 / #827 — inverse problem where the header causes 403 for non-project-member OAuth users

Suggested fix

Add x-goog-user-project via auth::get_quota_project() in fetch_message_metadata (and other helper functions that bypass executor.rs). Same trade-off as #729 applies.

Alternatively, refactor helpers to route through executor.rs or a shared request-building function that handles auth headers consistently.

Workaround

gws gmail users messages get --params '{"userId":"me","id":"<message-id>","format":"full"}'

Environment

  • gws 0.22.5, macOS (Apple Silicon)
  • Auth: OAuth desktop, keyring backend
  • Confirmed with both gmail.modify only and gmail.modify + gmail.readonly
  • ADC quota_project_id set to a project with Gmail API enabled (irrelevant — build_client() does not propagate it)
Dominant language
Rust
Stars
32.3k
Forks
2k
Avg merge
16h 3m
Merged PRs (30d)
1

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from googleworkspace/cli

All issues in googleworkspace/cli

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.