Skip to content

Token cache invalidation #764

@snacsnoc

Description

@snacsnoc

Environment:

  • CLI Version: 0.22.5 installed via homebrew
  • OS: macOS
  • Auth method: OAuth desktop app
  • Keyring backend: keyring

Description:

After re-authenticating with additional scopes, gws auth status shows the new scopes in credentials.enc, but API calls can still use the old cached access token from:

~/.config/gws/token_cache.json

This caused a persistent 403 until I deleted the token cache manually.

Steps to reproduce:

  1. Authenticate with a basic scope, for example Drive:
gws auth login --scopes \
'https://www.googleapis.com/auth/drive.readonly,openid,https://www.googleapis.com/auth/userinfo.email,https://www.googleapis.com/auth/userinfo.profile'
  1. Run any command that populates the token cache:
gws drive files list --params '{"pageSize":1}'
  1. Re-authenticate with an additional scope:
gws auth login --scopes \
'https://www.googleapis.com/auth/drive.readonly,https://www.googleapis.com/auth/admin.reports.audit.readonly,openid,https://www.googleapis.com/auth/userinfo.email,https://www.googleapis.com/auth/userinfo.profile'
  1. Confirm gws auth status shows the new scope.

  2. Immediately run a command that requires the new scope:

gws admin-reports activities list \
  --params '{"userKey":"all","applicationName":"login","maxResults":1}'

Observed:

The command fails:

{
  "error": {
    "code": 403,
    "message": "Request had insufficient authentication scopes.",
    "reason": "insufficientPermissions"
  }
}

Deleting the token cache fixes it:

rm ~/.config/gws/token_cache.json

After deleting the cache, the same command succeeds

Expected:
After a successful gws auth login, any cached access token using the previous scope set should be invalidated. The next API call should mint a new access token using the newly saved credentials/scopes

Thoughts:
After handle_login_inner successfully saves new credentials, invalidate/delete token_cache.json

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions