mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #318] [MERGED] feat: add Spotify OAuth redirect URI handling and manual paste-back s… #4558
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#4558
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/318
Author: @LightD31
Created: 4/29/2026
Status: ✅ Merged
Merged: 5/3/2026
Merged by: @SpicyMarinara
Base:
main← Head:main📝 Commits (7)
61082defeat: add Spotify OAuth redirect URI handling and manual paste-back support for LAN installsa0bfb60fix(spotify): address review feedback on PR #3189a5cc13fix(spotify): re-read agent settings before persisting tokense0051bbfix(spotify): enforce PKCE TTL inside completeExchange465d3c3chore(spotify): trim comments to match surrounding style9026504fix(spotify): tidy review nits on PR #31860b5de1Merge branch 'main' into main📊 Changes
7 files changed (+392 additions, -150 deletions)
View changed files
📝
.env.example(+10 -0)📝
docs/CONFIGURATION.md(+1 -0)📝
docs/FAQ.md(+4 -0)📝
docs/TROUBLESHOOTING.md(+13 -0)📝
packages/client/src/components/agents/AgentEditor.tsx(+162 -41)📝
packages/server/src/config/runtime-config.ts(+48 -1)📝
packages/server/src/routes/spotify-auth.routes.ts(+154 -108)📄 Description
feat: add Spotify OAuth redirect URI handling and manual paste-back
Linked issue
Closes #317
Why this change
The Spotify DJ agent's OAuth callback was hardcoded to
http://127.0.0.1:<PORT>/api/spotify/callback. When Marinara runs on a different machine than the browser (LAN install, remote server, Tailscale, phone-on-Wi-Fi), Spotify redirects the popup to127.0.0.1on the browser's machine — where nothing is listening — and the connect flow silently times out.A naive "use the LAN IP" fix doesn't work either: Spotify's Feb 2025 policy only accepts
https://<any-host>or the loopback literalshttp://127.0.0.1/http://[::1]as registered redirect URIs.localhostand LAN IPs are rejected at registration. So the fix has to cover both auto-deriving the right URI when it can legally be derived (HTTPS deployments) and providing a usable manual fallback when it can't (plain-HTTP LAN).What changed
getSpotifyRedirectUri()inpackages/server/src/config/runtime-config.tswithbuildSpotifyRedirectUri(req). Honours aSPOTIFY_REDIRECT_URIenv override; otherwise pickshttps://<host>/...for HTTPS requests (includingX-Forwarded-Proto: httpsfrom a reverse proxy),http://<host>/...only when the host is a loopback literal, and falls back tohttp://127.0.0.1:<PORT>/...for everything else (the only HTTP form Spotify accepts).POST /api/spotify/exchangeinpackages/server/src/routes/spotify-auth.routes.tsaccepts either a full callback URL or pre-extractedcode+state, validates against the existing PKCEpendingAuthmap, and runs the same token exchange the redirect callback uses (factored into a sharedcompleteExchangehelper to avoid drift). 10-minute pending-auth window unchanged.packages/client/src/components/agents/AgentEditor.tsx, added a collapsed "Browser couldn't reach the callback?" disclosure (only shown while a connection is in flight) with a textarea, error display, and Submit button that POSTs to/api/spotify/exchange. Replaced the hardcodedhttp://127.0.0.1:7860/...fallback display with${window.location.origin}/api/spotify/callback. Added a short note explaining Spotify's loopback-or-HTTPS constraint so users understand why the registered URI may not match where they're browsing.SPOTIFY_REDIRECT_URIto.env.exampleanddocs/CONFIGURATION.md, a new "Spotify DJ Login Fails on a Remote or LAN Install" section indocs/TROUBLESHOOTING.mdcovering all four deployment shapes, and a one-paragraph cross-link from the LAN-access entry indocs/FAQ.md.Validation
pnpm checkpasses locallyCONTRIBUTING.mdManual verification notes
Treat the items below as a to-do list — tick each only after running it yourself.
pnpm dev, browsehttp://127.0.0.1:7860, agent editor shows redirect URIhttp://127.0.0.1:7860/api/spotify/callback, full Connect → popup → token exchange completes via the existing redirect handler.SSL_CERT/SSL_KEYset, browsehttps://localhost:7860, agent editor showshttps://localhost:7860/api/spotify/callback, register that URI in the Spotify Developer Dashboard, full Connect flow completes.curl -H 'X-Forwarded-Proto: https' -H 'X-Forwarded-Host: marinara.example.com' http://127.0.0.1:7860/api/spotify/status?agentId=spotifyreturnsredirectUri: "https://marinara.example.com/api/spotify/callback".SPOTIFY_REDIRECT_URI=https://music.example.com/api/spotify/callbackin.env, restart, confirm both/api/spotify/statusand the agent editor display that exact string.HOST=0.0.0.0 pnpm starton machine A; browser on machine B athttp://<machine-A-IP>:7860; agent editor displays the loopback URI plus the explanatory note; register the loopback URI in Spotify; click Connect; popup lands on a connection-refused page on machine B; copy the full URL from the popup's address bar; expand "Browser couldn't reach the callback?" and paste; click Complete connection → status flips to connected.Docs and release impact
Updated
.env.example,docs/CONFIGURATION.md,docs/TROUBLESHOOTING.md, anddocs/FAQ.md. No version bump (bug fix).UI evidence (if applicable)
Summary by CodeRabbit
New Features
Documentation
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.