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

Offen Anfängerfreundlich
#984 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
80/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
rust
Bereich
authentication, cli

Rechercherichtung

Beginne in crates/google-workspace-cli/src/auth_commands.rs bei handle_login_inner, wo die neuen Anmeldedaten gespeichert werden, und vergleiche es mit handle_logout, das den Cache bereits löscht. Füge nach dem Speichern das Entfernen von token_cache.json und sa_token_cache.json hinzu und prüfe dann select_scope in main.rs, um zu bestätigen, wie gecachte Tokens nach Scope-Set verschlüsselt werden. Fertig, wenn eine erneute Anmeldung mit einem breiteren Scope und der Aufruf einer Gmail-Methode keinen 403 mehr zurückgibt und die Auth-Tests bestehen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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
Vorherrschende Sprache
Rust
Sterne
32.3k
Forks
2k
Ø Merge
16 Std. 3 Min.
Gemergte PRs (30 T.)
1

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus googleworkspace/cli

Alle Issues in googleworkspace/cli

Ähnliche Issues

Weitere Issues zu Rust

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.