Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 13, 2025

SpotifyOAuth's default behavior starts an HTTP server on port 5000 for OAuth callbacks, conflicting with the Flask app and causing [Errno 98] Address already in use in Docker deployments.

Spotify Authentication Fix

Core changes:

  • Added /callback route to handle OAuth redirects within Flask app
  • Set open_browser=False in SpotifyOAuth to prevent local server conflicts
  • Implemented persistent token caching in /config/.spotify_cache
  • Added web-based authentication flow with UI button and API endpoints

Files modified:

  • app/utils/spotify_manager.py - OAuth callback handling, cache path
  • app/routes/web.py - /callback route, /api/spotify/auth-url endpoint
  • app/core/sync_engine.py - Auth URL generation, callback delegation
  • app/templates/index.html + app/static/js/app.js - Authentication UI

Authentication flow:

# SpotifyManager now accepts cache_path and prevents browser conflicts
self._auth_manager = SpotifyOAuth(
    client_id=self.client_id,
    client_secret=self.client_secret,
    redirect_uri=self.redirect_uri,
    scope=self.scope,
    cache_path=self.cache_path,
    open_browser=False  # Key fix for Docker
)

Users click "Authenticate with Spotify" → redirected to Spotify → callback to /callback → token cached and persisted.

Home Assistant Integration Mode

Added dual-mode support to HA addon: standalone (original full-app) and integration (HTTP proxy to external Docker server).

Implementation:

  • homeassistant/spotifytowled/config.json - Added mode and server_url options
  • homeassistant/spotifytowled/run.sh - Mode detection with Flask proxy for integration mode

Integration mode configuration:

mode: "integration"
server_url: "http://192.168.1.50:5000"

Proxy forwards all requests to external Docker server, enabling centralized management across multiple HA instances with minimal resource usage.

Backward Compatibility

All v2.0 configurations work unchanged. Standalone mode is default. No breaking changes.

Security: CodeQL analysis passed (0 vulnerabilities)

Original prompt

This section details on the original issue you should resolve

<issue_title>Docker Spotify issue</issue_title>
<issue_description>2025-11-13 13:44:07,728 - app.main - WARNING - ⚠️ Default secret key is being used! This is insecure for production. Please set SECRET_KEY in your configuration.
2025-11-13 13:44:07,732 - app.main - INFO - SpotifyToWLED v2.0.0 initialized
2025-11-13 13:44:07,732 - app.main - INFO - Starting server on port 5000

  • Serving Flask app 'app.main'
  • Debug mode: off
    2025-11-13 13:44:07,733 - werkzeug - INFO - WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
  • Running on all addresses (0.0.0.0)
  • Running on http://127.0.0.1:5000
  • Running on http://192.168.68.155:5000
    2025-11-13 13:44:07,734 - werkzeug - INFO - Press CTRL+C to quit
    2025-11-13 13:44:12,494 - werkzeug - INFO - 127.0.0.1 - - [13/Nov/2025 13:44:12] "GET /health HTTP/1.1" 200 -
    2025-11-13 13:44:42,675 - werkzeug - INFO - 127.0.0.1 - - [13/Nov/2025 13:44:42] "GET /health HTTP/1.1" 200 -
    2025-11-13 13:44:55,484 - werkzeug - INFO - 192.168.68.120 - - [13/Nov/2025 13:44:55] "GET / HTTP/1.1" 200 -
    2025-11-13 13:44:55,592 - werkzeug - INFO - 192.168.68.120 - - [13/Nov/2025 13:44:55] "GET /static/js/app.js HTTP/1.1" 200 -
    2025-11-13 13:44:55,593 - werkzeug - INFO - 192.168.68.120 - - [13/Nov/2025 13:44:55] "GET /static/css/style.css HTTP/1.1" 200 -
    2025-11-13 13:44:56,635 - werkzeug - INFO - 192.168.68.120 - - [13/Nov/2025 13:44:56] "GET /favicon.ico HTTP/1.1" 404 -
    2025-11-13 13:45:12,862 - werkzeug - INFO - 127.0.0.1 - - [13/Nov/2025 13:45:12] "GET /health HTTP/1.1" 200 -
    2025-11-13 13:45:43,038 - werkzeug - INFO - 127.0.0.1 - - [13/Nov/2025 13:45:43] "GET /health HTTP/1.1" 200 -
    2025-11-13 13:46:00,246 - app.core.config - INFO - Configuration saved to /config/config.json
    2025-11-13 13:46:00,247 - werkzeug - INFO - 192.168.68.120 - - [13/Nov/2025 13:46:00] "POST /api/config/update HTTP/1.1" 302 -
    2025-11-13 13:46:00,258 - werkzeug - INFO - 192.168.68.120 - - [13/Nov/2025 13:46:00] "GET / HTTP/1.1" 200 -
    2025-11-13 13:46:00,329 - werkzeug - INFO - 192.168.68.120 - - [13/Nov/2025 13:46:00] "GET /static/js/app.js HTTP/1.1" 304 -
    2025-11-13 13:46:00,329 - werkzeug - INFO - 192.168.68.120 - - [13/Nov/2025 13:46:00] "GET /static/css/style.css HTTP/1.1" 304 -
    2025-11-13 13:46:13,219 - werkzeug - INFO - 127.0.0.1 - - [13/Nov/2025 13:46:13] "GET /health HTTP/1.1" 200 -
    2025-11-13 13:46:19,153 - werkzeug - INFO - 192.168.68.120 - - [13/Nov/2025 13:46:19] "GET / HTTP/1.1" 200 -
    2025-11-13 13:46:19,202 - werkzeug - INFO - 192.168.68.120 - - [13/Nov/2025 13:46:19] "GET /static/css/style.css HTTP/1.1" 200 -
    2025-11-13 13:46:19,203 - werkzeug - INFO - 192.168.68.120 - - [13/Nov/2025 13:46:19] "GET /static/js/app.js HTTP/1.1" 200 -
    2025-11-13 13:46:19,652 - werkzeug - INFO - 192.168.68.120 - - [13/Nov/2025 13:46:19] "GET /favicon.ico HTTP/1.1" 404 -
    2025-11-13 13:46:29,721 - app.core.sync_engine - ERROR - Invalid configuration: At least one WLED IP address is required
    2025-11-13 13:46:29,721 - werkzeug - INFO - 192.168.68.120 - - [13/Nov/2025 13:46:29] "POST /api/sync/start HTTP/1.1" 400 -
    2025-11-13 13:46:43,402 - werkzeug - INFO - 127.0.0.1 - - [13/Nov/2025 13:46:43] "GET /health HTTP/1.1" 200 -
    2025-11-13 13:47:03,941 - app.core.config - INFO - Configuration saved to /config/config.json
    2025-11-13 13:47:03,942 - werkzeug - INFO - 192.168.68.120 - - [13/Nov/2025 13:47:03] "POST /api/wled/add HTTP/1.1" 302 -
    2025-11-13 13:47:03,946 - werkzeug - INFO - 192.168.68.120 - - [13/Nov/2025 13:47:03] "GET / HTTP/1.1" 200 -
    2025-11-13 13:47:03,963 - werkzeug - INFO - 192.168.68.120 - - [13/Nov/2025 13:47:03] "GET /static/css/style.css HTTP/1.1" 304 -
    2025-11-13 13:47:03,964 - werkzeug - INFO - 192.168.68.120 - - [13/Nov/2025 13:47:03] "GET /static/js/app.js HTTP/1.1" 304 -
    2025-11-13 13:47:08,127 - werkzeug - INFO - 192.168.68.120 - - [13/Nov/2025 13:47:08] "GET /api/wled/health?ip=192.168.68.102 HTTP/1.1" 200 -
    2025-11-13 13:47:13,581 - werkzeug - INFO - 127.0.0.1 - - [13/Nov/2025 13:47:13] "GET /health HTTP/1.1" 200 -
    2025-11-13 13:47:18,691 - app.core.config - INFO - Configuration saved to /config/config.json
    2025-11-13 13:47:18,691 - werkzeug - INFO - 192.168.68.120 - - [13/Nov/2025 13:47:18] "POST /api/wled/add HTTP/1.1" 302 -
    2025-11-13 13:47:18,694 - werkzeug - INFO - 192.168.68.120 - - [13/Nov/2025 13:47:18] "GET / HTTP/1.1" 200 -
    2025-11-13 13:47:18,720 - werkzeug - INFO - 192.168.68.120 - - [13/Nov/2025 13:47:18] "GET /static/css/style.css HTTP/1.1" 304 -
    2025-11-13 13:47:18,721 - werkzeug - INFO - 192.168.68.120 - - [13/Nov/2025 13:47:18] "GET /static/js/app.js HTTP/1.1" 304 -
    2025-11-13 13:47:28,759 - app.core.config - INFO - Configuration saved to /config/config.json
    2025-11-13 13:47:28,759 - werkzeug - INFO - 192.168.68.120 - - [13/Nov/2025 13:47:28] "POST /api/wled/add HTTP/1.1" 302 -
    2025-11-13 13:47:28,763 - werkzeug - INFO - 192.168.68.120 - - [13/Nov...

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 4 commits November 13, 2025 12:53
Co-authored-by: raphaelbleier <75416341+raphaelbleier@users.noreply.github.com>
Co-authored-by: raphaelbleier <75416341+raphaelbleier@users.noreply.github.com>
Co-authored-by: raphaelbleier <75416341+raphaelbleier@users.noreply.github.com>
Co-authored-by: raphaelbleier <75416341+raphaelbleier@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix insecure default secret key for production Fix Docker Spotify OAuth and add Home Assistant integration mode Nov 13, 2025
Copilot AI requested a review from raphaelbleier November 13, 2025 13:04
@raphaelbleier raphaelbleier marked this pull request as ready for review November 13, 2025 13:33
@raphaelbleier raphaelbleier merged commit 4a2673a into main Nov 13, 2025
2 checks passed
@raphaelbleier raphaelbleier deleted the copilot/set-secret-key-for-production branch November 13, 2025 13:35
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.

Docker Spotify issue

2 participants