Skip to content

Self-heal revoked Spotify refresh tokens in cmd/spotify - #342

Merged
drn merged 2 commits into
masterfrom
argus/hs-music-spotify-cli
Sep 4, 2026
Merged

drn merged 2 commits into
masterfrom
argus/hs-music-spotify-cli

Conversation

@drn

@drn drn commented Sep 4, 2026

Copy link
Copy Markdown
Owner

cmd/spotify's OAuth flow used to exit with a raw API error when the cached refresh token was revoked, requiring manual editing of ~/.dots/sys/config to recover. FetchAccessToken now detects a genuine invalid_grant, clears the stale cache, and re-authorizes automatically (capped at one retry). Other token-endpoint failures (5xx, rate limits) still exit without touching an otherwise-good cached refresh token. Adds context/ per the /improve convention, documenting why Spotify's save/remove/transfer require the Web API while everything else stays on Hammerspoon's AppleScript-backed hs.spotify.

Co-Authored-By: Claude noreply@anthropic.com

drn and others added 2 commits September 4, 2026 11:20
cmd/spotify's OAuth flow used to exit with a raw API error when the cached
refresh token was revoked, requiring manual config editing to recover.
FetchAccessToken now clears the stale cache and re-authorizes automatically.

Also adds context/ per the /improve convention, capturing why Spotify's
save/remove/transfer need a separate Web API client while everything else
can stay on Hammerspoon's AppleScript-backed hs.spotify.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…transient

- Cap the revoked-refresh-token recovery to one retry via an explicit
  isRetry parameter instead of open-ended recursion, so a persistently
  failing config.Delete write can't loop forever against Spotify's token
  endpoint.
- Only treat a 400 invalid_grant response as "revoked" (safe to clear the
  cache and re-authorize); any other failure (5xx, rate limit, etc.) now
  exits without destroying an otherwise-good cached refresh token.
- Route exchangeAuthorizationCode's failure path through the same
  log.Error-based exitOnTokenError helper as the new non-revoked failure
  path in exchangeRefreshToken, instead of a one-off fmt.Println.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@drn
drn merged commit 98e981e into master Sep 4, 2026
@drn
drn deleted the argus/hs-music-spotify-cli branch September 4, 2026 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant