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

Ouverte Adaptée aux débutants
#984 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
80/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
rust
Domaine
authentication, cli

Piste de recherche

Commence dans crates/google-workspace-cli/src/auth_commands.rs à handle_login_inner, où les nouveaux identifiants sont enregistrés, et compare-le avec handle_logout, qui supprime déjà le cache. Ajoute la suppression de token_cache.json et sa_token_cache.json après l'enregistrement, puis vérifie select_scope dans main.rs pour confirmer comment les tokens en cache sont indexés par ensemble de scopes. Terminé lorsque se reconnecter avec un scope plus large et appeler une méthode Gmail ne renvoie plus 403, avec les tests d'authentification qui passent.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

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_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
Langage dominant
Rust
Étoiles
32.3k
Forks
2k
Merge moyen
16 h 3 min
PR mergées (30 j)
1

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de googleworkspace/cli

Toutes les issues de googleworkspace/cli

Issues similaires

Plus d'issues Rust

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.