From 21d016fcbd5af6cf87884b797e75c9aaad276e1e Mon Sep 17 00:00:00 2001 From: Broque Thomas Date: Fri, 12 Sep 2025 21:56:26 -0700 Subject: [PATCH] Add configurable redirect URI for Spotify and Tidal Redirect URIs for Spotify and Tidal OAuth are now configurable via the web UI and settings. Updated backend clients to use the configured redirect URI if provided, improving flexibility for deployments with custom callback URLs. --- core/spotify_client.py | 2 +- core/tidal_client.py | 3 ++- web_server.py | 2 +- webui/index.html | 16 ++++++++++++---- webui/static/script.js | 19 +++++++++++++++++-- 5 files changed, 33 insertions(+), 9 deletions(-) diff --git a/core/spotify_client.py b/core/spotify_client.py index 7c04c23..cf4170d 100644 --- a/core/spotify_client.py +++ b/core/spotify_client.py @@ -172,7 +172,7 @@ class SpotifyClient: auth_manager = SpotifyOAuth( client_id=config['client_id'], client_secret=config['client_secret'], - redirect_uri="http://127.0.0.1:8888/callback", + redirect_uri=config.get('redirect_uri', "http://127.0.0.1:8888/callback"), scope="user-library-read user-read-private playlist-read-private playlist-read-collaborative user-read-email", cache_path='config/.spotify_cache' ) diff --git a/core/tidal_client.py b/core/tidal_client.py index 8723400..1689d27 100644 --- a/core/tidal_client.py +++ b/core/tidal_client.py @@ -98,7 +98,7 @@ class TidalClient: self.alt_base_url = "https://api.tidal.com/v1" # Alternative API base self.auth_url = "https://login.tidal.com/authorize" self.token_url = "https://auth.tidal.com/v1/oauth2/token" - self.redirect_uri = "http://127.0.0.1:8889/tidal/callback" + self.redirect_uri = "http://127.0.0.1:8889/tidal/callback" # Default, will be updated from config self.session = requests.Session() self.auth_server = None self.auth_code = None @@ -117,6 +117,7 @@ class TidalClient: tidal_config = config_manager.get('tidal', {}) self.client_id = tidal_config.get('client_id') self.client_secret = tidal_config.get('client_secret') + self.redirect_uri = tidal_config.get('redirect_uri', self.redirect_uri) # Use config or default if not self.client_id or not self.client_secret: logger.warning("Tidal client ID or secret not configured") diff --git a/web_server.py b/web_server.py index bfa37ba..4b3651a 100644 --- a/web_server.py +++ b/web_server.py @@ -11349,7 +11349,7 @@ def start_oauth_callback_servers(): auth_manager = SpotifyOAuth( client_id=config['client_id'], client_secret=config['client_secret'], - redirect_uri="http://127.0.0.1:8888/callback", + redirect_uri=config.get('redirect_uri', "http://127.0.0.1:8888/callback"), scope="user-library-read user-read-private playlist-read-private playlist-read-collaborative user-read-email", cache_path='config/.spotify_cache' ) diff --git a/webui/index.html b/webui/index.html index 9150d1c..4e28066 100644 --- a/webui/index.html +++ b/webui/index.html @@ -652,9 +652,13 @@ +
+ + +
-
Required Redirect URI:
-
http://127.0.0.1:8888/callback
+
Current Redirect URI:
+
http://127.0.0.1:8888/callback
Add this URL to your Spotify app's 'Redirect URIs' in the Spotify Developer Dashboard
@@ -673,9 +677,13 @@
+
+ + +
-
Required Redirect URI:
-
http://127.0.0.1:8889/tidal/callback
+
Current Redirect URI:
+
http://127.0.0.1:8889/tidal/callback
Add this URL to your Tidal app configuration
diff --git a/webui/static/script.js b/webui/static/script.js index 4b49f4c..78e4d8f 100644 --- a/webui/static/script.js +++ b/webui/static/script.js @@ -1347,10 +1347,23 @@ async function loadSettingsData() { // Populate Spotify settings document.getElementById('spotify-client-id').value = settings.spotify?.client_id || ''; document.getElementById('spotify-client-secret').value = settings.spotify?.client_secret || ''; + document.getElementById('spotify-redirect-uri').value = settings.spotify?.redirect_uri || 'http://127.0.0.1:8888/callback'; + document.getElementById('spotify-callback-display').textContent = settings.spotify?.redirect_uri || 'http://127.0.0.1:8888/callback'; // Populate Tidal settings document.getElementById('tidal-client-id').value = settings.tidal?.client_id || ''; document.getElementById('tidal-client-secret').value = settings.tidal?.client_secret || ''; + document.getElementById('tidal-redirect-uri').value = settings.tidal?.redirect_uri || 'http://127.0.0.1:8889/tidal/callback'; + document.getElementById('tidal-callback-display').textContent = settings.tidal?.redirect_uri || 'http://127.0.0.1:8889/tidal/callback'; + + // Add event listeners to update display URLs when input changes + document.getElementById('spotify-redirect-uri').addEventListener('input', function() { + document.getElementById('spotify-callback-display').textContent = this.value || 'http://127.0.0.1:8888/callback'; + }); + + document.getElementById('tidal-redirect-uri').addEventListener('input', function() { + document.getElementById('tidal-callback-display').textContent = this.value || 'http://127.0.0.1:8889/tidal/callback'; + }); // Populate Plex settings document.getElementById('plex-url').value = settings.plex?.base_url || ''; @@ -1426,11 +1439,13 @@ async function saveSettings() { active_media_server: activeServer, spotify: { client_id: document.getElementById('spotify-client-id').value, - client_secret: document.getElementById('spotify-client-secret').value + client_secret: document.getElementById('spotify-client-secret').value, + redirect_uri: document.getElementById('spotify-redirect-uri').value }, tidal: { client_id: document.getElementById('tidal-client-id').value, - client_secret: document.getElementById('tidal-client-secret').value + client_secret: document.getElementById('tidal-client-secret').value, + redirect_uri: document.getElementById('tidal-redirect-uri').value }, plex: { base_url: document.getElementById('plex-url').value,