spotify: capture OAuth code via local loopback server#317
Merged
Conversation
Replace the manual copy-paste auth flow (which relied on an external relay page as the redirect target) with the standard OAuth loopback redirect. The CLI now starts a local HTTP server on the redirect URI's port, opens the browser to Spotify's consent screen, and captures the authorization code automatically from the callback. - authorize() parses SPOTIFY_REDIRECT_URI, binds a loopback listener on its port, sends a random CSRF state, and returns the captured code. - captureAuthCode() serves the callback, validates state, surfaces error/missing-code cases, and enforces a 2-minute timeout. - Drop inputCode/validateInput and the promptui dependency here. - SPOTIFY_REDIRECT_URI must now be a loopback URL with an explicit port (e.g. http://127.0.0.1:8888/callback) registered on the Spotify app. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Address review findings on the loopback auth flow:
- Open the browser via exec.Command("open", url) instead of building a
zsh -c string, so the auth URL is never interpreted by a shell.
- Validate that SPOTIFY_REDIRECT_URI is a loopback host (127.0.0.1,
::1, or localhost), not just that it has a port — previously a
non-loopback host would still be sent to Spotify as the redirect.
- Bind the listener to the redirect URI's own host:port so it matches
the address the browser is redirected to.
- Shut down the callback server gracefully (Shutdown with a 2s grace)
so the "you can close this tab" response flushes before teardown.
- Guard the result delivery with sync.Once so a browser retry/refresh
that re-hits the handler can't block on a channel send forever.
- Give net.Listen / randomState failures contextual error messages.
Add tests for isLoopback.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
70e8223 to
9f65ea6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace the manual copy-paste OAuth flow (which used an external relay page as the redirect target) with the standard OAuth loopback redirect. The CLI now starts a local HTTP server on the redirect URI's port, opens the browser to Spotify's consent screen, and captures the authorization code automatically from the callback.
Co-Authored-By: Claude noreply@anthropic.com