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

Đang mở Phù hợp với người mới
#984 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
80/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust
Lĩnh vực
authentication, cli

Hướng nghiên cứu

Bắt đầu trong crates/google-workspace-cli/src/auth_commands.rs tại handle_login_inner, nơi thông tin xác thực mới được lưu, và so sánh với handle_logout, nơi đã xóa bộ nhớ đệm. Thêm việc xóa token_cache.json và sa_token_cache.json sau khi lưu, sau đó kiểm tra select_scope trong main.rs để xác nhận cách các token được lưu trong bộ nhớ đệm được khóa theo tập hợp scope. Hoàn thành khi đăng nhập lại với scope rộng hơn và gọi một phương thức Gmail không còn trả về 403, với các bài kiểm thử xác thực đều vượt qua.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
Rust
Star
32.3k
Fork
2k
Merge trung bình
16 giờ 3 phút
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của googleworkspace/cli

Tất cả issue của googleworkspace/cli

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.