`gws auth login` keeps the old token cache, so API calls use a token from the previous grant

オープン 初心者向け
#984 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
80/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
rust

調査の方向性

crates/google-workspace-cli/src/auth_commands.rs の handle_login_inner(新しい認証情報が保存される場所)から始め、すでにキャッシュを削除している handle_logout と比較してください。保存後に token_cache.json と sa_token_cache.json の削除を追加し、次に main.rs の select_scope を確認して、キャッシュされたトークンがスコープセットごとにどのようにキー付けされるかを確かめてください。より広いスコープで再度ログインし、Gmail のメソッドを呼び出しても 403 が返らなくなり、認証テストが通れば完了です。

索引モデルが issue の本文から書いたものです。

説明

This report was written by an AI coding agent (Claude Code) that diagnosed the fault on its user's machine. "The agent" below is that agent.

Observed

On the user's machine, after gws auth login, API calls kept failing with 403 errors although gws auth status reported the correct scopes and "token_valid": true.

$ gws gmail users drafts create --params '{"userId":"me"}' --json '{"message":{"raw":"..."}}'
{
  "error": {
    "code": 403,
    "message": "Missing access token for authorization. Request: MailboxService.CreateDraft",
    "reason": "forbidden"
  }
}

$ gws gmail users messages modify --params '{"userId":"me","id":"..."}' --json '{"addLabelIds":["STARRED"]}'
{
  "error": {
    "code": 403,
    "message": "Request had insufficient authentication scopes."
  }
}

In the same state, gmail users messages list, gmail users labels create and gmail users messages insert succeeded, and gws auth status listed https://www.googleapis.com/auth/gmail.modify.

The files in the config directory showed that the login had written new credentials and left the cache:

credentials.enc    10:47
token_cache.json   10:45

The agent moved token_cache.json aside, and every call then succeeded.

Expected

gws auth login replaces the credentials, so the next API call uses a token from the new grant.

Cause

  • handle_login_inner in crates/google-workspace-cli/src/auth_commands.rs saves the new credentials and does not touch token_cache.json. Only handle_logout deletes it.
  • select_scope in main.rs asks for the first scope of each method, and the cache stores one token for each scope set. Every Gmail method lists https://mail.google.com/ first, so all Gmail calls share one cached entry.
  • gws auth status gets a new token for its tokeninfo check, so it reports the new grant while API calls still use the cached token.

Steps to reproduce

The agent observed the end state above and did not run this exact sequence:

  1. gws auth login with a narrow scope set, then call a Gmail method so a token is cached.
  2. gws auth login again with a wider scope set.
  3. Call a method that needs the new scope. It fails with a 403 until the cached token is replaced.

Proposed fix

Delete token_cache.json and sa_token_cache.json in the login path, after the new credentials are saved.

Related

#188 reported the same symptom and was closed with a manual workaround (delete the stale cache).

Environment

  • gws 0.22.5, built from source
  • macOS, keyring backend
    the scratch file is removed; the text on stdout is the only copy
主要言語
Rust
スター
32.3k
フォーク
2k
平均マージ
16時間 3分
マージ済み PR(30日)
1

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

googleworkspace/cli のほかの issue

googleworkspace/cli の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。