fix: use gmail.readonly scope in +triage to avoid metadata scope 403 (#304)
The +triage helper uses the `q` query parameter when listing messages, but Gmail's metadata scope does not support `q` and returns 403. When a user's OAuth token includes both gmail.metadata and gmail.modify scopes, the API may resolve to the metadata code path and reject the query. Switch +triage from gmail.modify to gmail.readonly, which is the minimum scope that supports query filtering and aligns with the read-only nature of the triage command. Fixes #265
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@googleworkspace/cli": patch
|
||||
---
|
||||
|
||||
Fix gmail +triage 403 error by using gmail.readonly scope instead of gmail.modify to avoid conflict with gmail.metadata scope that does not support the q parameter
|
||||
@@ -38,6 +38,7 @@ use std::pin::Pin;
|
||||
pub struct GmailHelper;
|
||||
|
||||
pub(super) const GMAIL_SCOPE: &str = "https://www.googleapis.com/auth/gmail.modify";
|
||||
pub(super) const GMAIL_READONLY_SCOPE: &str = "https://www.googleapis.com/auth/gmail.readonly";
|
||||
pub(super) const PUBSUB_SCOPE: &str = "https://www.googleapis.com/auth/pubsub";
|
||||
|
||||
pub(super) struct OriginalMessage {
|
||||
|
||||
@@ -32,8 +32,12 @@ pub async fn handle_triage(matches: &ArgMatches) -> Result<(), GwsError> {
|
||||
.map(|s| crate::formatter::OutputFormat::from_str(s))
|
||||
.unwrap_or(crate::formatter::OutputFormat::Table);
|
||||
|
||||
// Authenticate
|
||||
let token = auth::get_token(&[GMAIL_SCOPE])
|
||||
// Authenticate — use gmail.readonly instead of gmail.modify because triage
|
||||
// is read-only and the `q` query parameter is not supported under the
|
||||
// gmail.metadata scope. When a token carries both metadata and modify
|
||||
// scopes the API may resolve to the metadata path and reject `q` with 403.
|
||||
// gmail.readonly always supports `q`.
|
||||
let token = auth::get_token(&[GMAIL_READONLY_SCOPE])
|
||||
.await
|
||||
.map_err(|e| GwsError::Auth(format!("Gmail auth failed: {e}")))?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user