fix: derive Spotify OAuth redirect URI from the request origin - #5368
Merged
Conversation
The Settings > Spotify panel told users to register http://localhost:5555/api/spotify/oauth/callback even when they had reached PortOS over a remote HTTPS Tailscale hostname, so the URI never matched what the browser would actually hit and the OAuth round-trip failed. getRedirectUri() now accepts an explicit origin, and every Spotify route passes the origin of the request it is serving (x-forwarded-proto/host first, then req.protocol/host). SPOTIFY_REDIRECT_URI still wins; the old PUBLIC_HOST and host-detection fallbacks stay in place for callers with no request context.
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.
Summary
http://localhost:5555/api/spotify/oauth/callbackeven when they had reached PortOS over a remote HTTPS hostname, so the redirect URI never matched what the browser would actually hit and the OAuth round-trip failed.getRedirectUri()now takes an explicit{ origin }, and every Spotify route passes the origin of the request it is serving (x-forwarded-proto/x-forwarded-hostfirst, thenreq.protocol/host). Authorize URL, callback token exchange, saved credentials, and the status payload all resolve to the same string.SPOTIFY_REDIRECT_URIstill wins verbatim, and thePUBLIC_HOST/ host-detection /localhostfallbacks stay for callers with no request context..env.exampleis updated to describe the new order.Test plan
server/routes/spotify.test.js(new) — asserts the status and authorize routes forward the forwarded-origin to the service layer.server/services/spotifyAuth.test.js— new case for an explicit origin, including trailing-slash normalization; existing precedence cases still pass.cd server && npm test— 35356 passed, 0 failed. ThreeimageGen.*suites andsprites/atlashit the 10s hook/test timeout under full-suite load; all four pass in isolation and are unrelated to this change.node scripts/generate-api-route-catalog.jsregeneratesapiRouteCatalog.generated.jsonwith no further diff (the committed change is line-number shifts only).