Skip to content

fix: derive Spotify OAuth redirect URI from the request origin - #5368

Merged
atomantic merged 1 commit into
mainfrom
cos/task-mtdsan3w/agent-8f0d4c86
Aug 29, 2026
Merged

fix: derive Spotify OAuth redirect URI from the request origin#5368
atomantic merged 1 commit into
mainfrom
cos/task-mtdsan3w/agent-8f0d4c86

Conversation

@atomantic

Copy link
Copy Markdown
Owner

Summary

  • 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 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-host first, then req.protocol/host). Authorize URL, callback token exchange, saved credentials, and the status payload all resolve to the same string.
  • Precedence is unchanged at the top and bottom: SPOTIFY_REDIRECT_URI still wins verbatim, and the PUBLIC_HOST / host-detection / localhost fallbacks stay for callers with no request context. .env.example is 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. Three imageGen.* suites and sprites/atlas hit 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.js regenerates apiRouteCatalog.generated.json with no further diff (the committed change is line-number shifts only).

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.
@atomantic
atomantic merged commit b586ac9 into main Aug 29, 2026
7 checks passed
@atomantic
atomantic deleted the cos/task-mtdsan3w/agent-8f0d4c86 branch August 29, 2026 03:45
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