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

Abierto Apto para principiantes
#984 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
80/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
rust

Línea de trabajo

Comienza en crates/google-workspace-cli/src/auth_commands.rs en handle_login_inner, donde se guardan las nuevas credenciales, y compáralo con handle_logout, que ya elimina la caché. Añade la eliminación de token_cache.json y sa_token_cache.json después del guardado, luego revisa select_scope en main.rs para confirmar cómo se indexan los tokens en caché por conjunto de scopes. Terminado cuando iniciar sesión de nuevo con un scope más amplio y llamar a un método de Gmail ya no devuelva 403, con las pruebas de autenticación pasando.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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
Lenguaje dominante
Rust
Estrellas
32.3k
Forks
2k
Merge medio
16 h 3 min
PR fusionados (30 d)
1

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de googleworkspace/cli

Todos los issues de googleworkspace/cli

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.