`gws auth login` keeps the old token cache, so API calls use a token from the previous grant
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 80/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- rust
- Domain
- authentication, cli
Research direction
Start in crates/google-workspace-cli/src/auth_commands.rs at handle_login_inner, where the new credentials are saved, and compare it with handle_logout, which already deletes the cache. Add removal of token_cache.json and sa_token_cache.json after the save, then check select_scope in main.rs to confirm how cached tokens are keyed by scope set. Done when logging in again with a wider scope and calling a Gmail method no longer returns 403, with the auth tests passing.
Written by the indexing model from the issue text.
Description
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_innerincrates/google-workspace-cli/src/auth_commands.rssaves the new credentials and does not touchtoken_cache.json. Onlyhandle_logoutdeletes it.select_scopeinmain.rsasks for the first scope of each method, and the cache stores one token for each scope set. Every Gmail method listshttps://mail.google.com/first, so all Gmail calls share one cached entry.gws auth statusgets a new token for itstokeninfocheck, 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:
gws auth loginwith a narrow scope set, then call a Gmail method so a token is cached.gws auth loginagain with a wider scope set.- 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
- Dominant language
- Rust
- Stars
- 32.3k
- Forks
- 2k
- Avg merge
- 16h 3m
- Merged PRs (30d)
- 1
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from googleworkspace/cli
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
googleworkspace/cli#983 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 82/100
googleworkspace/cli#958 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
googleworkspace/cli#921 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
googleworkspace/cli#920 ·
Maintainers usually reply within 1 day
-
docs(gmail): the --draft tip prints a send command that fails (users.drafts.send --body)May be free again A pull request for this issue was closed without being merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
googleworkspace/cli#914 · 1 comment ·
Maintainers usually reply within 1 day
All issues in googleworkspace/cli
Similar issues
-
area:cli area:security bug priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
status: new topic: ga4gh-sdk type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
comp-rbac
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
ClickHouse/ClickHouse#131875 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Maintainers usually reply within 1 day
-
bug(python): read_transaction raises TypeError on a Rewrite with rewritten indicesPossibly taken @Borg93 claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
lance-format/lance#11117 ·
Maintainers usually reply within 2 days