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.
This commit is contained in:
Broque Thomas 2025-09-12 21:56:26 -07:00
parent 93ac55a709
commit 21d016fcbd
5 changed files with 33 additions and 9 deletions

View file

@ -172,7 +172,7 @@ class SpotifyClient:
auth_manager = SpotifyOAuth( auth_manager = SpotifyOAuth(
client_id=config['client_id'], client_id=config['client_id'],
client_secret=config['client_secret'], 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", scope="user-library-read user-read-private playlist-read-private playlist-read-collaborative user-read-email",
cache_path='config/.spotify_cache' cache_path='config/.spotify_cache'
) )

View file

@ -98,7 +98,7 @@ class TidalClient:
self.alt_base_url = "https://api.tidal.com/v1" # Alternative API base self.alt_base_url = "https://api.tidal.com/v1" # Alternative API base
self.auth_url = "https://login.tidal.com/authorize" self.auth_url = "https://login.tidal.com/authorize"
self.token_url = "https://auth.tidal.com/v1/oauth2/token" 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.session = requests.Session()
self.auth_server = None self.auth_server = None
self.auth_code = None self.auth_code = None
@ -117,6 +117,7 @@ class TidalClient:
tidal_config = config_manager.get('tidal', {}) tidal_config = config_manager.get('tidal', {})
self.client_id = tidal_config.get('client_id') self.client_id = tidal_config.get('client_id')
self.client_secret = tidal_config.get('client_secret') 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: if not self.client_id or not self.client_secret:
logger.warning("Tidal client ID or secret not configured") logger.warning("Tidal client ID or secret not configured")

View file

@ -11349,7 +11349,7 @@ def start_oauth_callback_servers():
auth_manager = SpotifyOAuth( auth_manager = SpotifyOAuth(
client_id=config['client_id'], client_id=config['client_id'],
client_secret=config['client_secret'], 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", scope="user-library-read user-read-private playlist-read-private playlist-read-collaborative user-read-email",
cache_path='config/.spotify_cache' cache_path='config/.spotify_cache'
) )

View file

@ -652,9 +652,13 @@
<label>Client Secret:</label> <label>Client Secret:</label>
<input type="password" id="spotify-client-secret" placeholder="Spotify Client Secret"> <input type="password" id="spotify-client-secret" placeholder="Spotify Client Secret">
</div> </div>
<div class="form-group">
<label>Redirect URI:</label>
<input type="text" id="spotify-redirect-uri" placeholder="http://127.0.0.1:8888/callback">
</div>
<div class="callback-info"> <div class="callback-info">
<div class="callback-label">Required Redirect URI:</div> <div class="callback-label">Current Redirect URI:</div>
<div class="callback-url">http://127.0.0.1:8888/callback</div> <div class="callback-url" id="spotify-callback-display">http://127.0.0.1:8888/callback</div>
<div class="callback-help">Add this URL to your Spotify app's 'Redirect URIs' in the Spotify Developer Dashboard</div> <div class="callback-help">Add this URL to your Spotify app's 'Redirect URIs' in the Spotify Developer Dashboard</div>
</div> </div>
<div class="form-actions"> <div class="form-actions">
@ -673,9 +677,13 @@
<label>Client Secret:</label> <label>Client Secret:</label>
<input type="password" id="tidal-client-secret" placeholder="Tidal Client Secret"> <input type="password" id="tidal-client-secret" placeholder="Tidal Client Secret">
</div> </div>
<div class="form-group">
<label>Redirect URI:</label>
<input type="text" id="tidal-redirect-uri" placeholder="http://127.0.0.1:8889/tidal/callback">
</div>
<div class="callback-info"> <div class="callback-info">
<div class="callback-label">Required Redirect URI:</div> <div class="callback-label">Current Redirect URI:</div>
<div class="callback-url">http://127.0.0.1:8889/tidal/callback</div> <div class="callback-url" id="tidal-callback-display">http://127.0.0.1:8889/tidal/callback</div>
<div class="callback-help">Add this URL to your Tidal app configuration</div> <div class="callback-help">Add this URL to your Tidal app configuration</div>
</div> </div>
<div class="form-actions"> <div class="form-actions">

View file

@ -1347,10 +1347,23 @@ async function loadSettingsData() {
// Populate Spotify settings // Populate Spotify settings
document.getElementById('spotify-client-id').value = settings.spotify?.client_id || ''; document.getElementById('spotify-client-id').value = settings.spotify?.client_id || '';
document.getElementById('spotify-client-secret').value = settings.spotify?.client_secret || ''; 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 // Populate Tidal settings
document.getElementById('tidal-client-id').value = settings.tidal?.client_id || ''; document.getElementById('tidal-client-id').value = settings.tidal?.client_id || '';
document.getElementById('tidal-client-secret').value = settings.tidal?.client_secret || ''; 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 // Populate Plex settings
document.getElementById('plex-url').value = settings.plex?.base_url || ''; document.getElementById('plex-url').value = settings.plex?.base_url || '';
@ -1426,11 +1439,13 @@ async function saveSettings() {
active_media_server: activeServer, active_media_server: activeServer,
spotify: { spotify: {
client_id: document.getElementById('spotify-client-id').value, 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: { tidal: {
client_id: document.getElementById('tidal-client-id').value, 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: { plex: {
base_url: document.getElementById('plex-url').value, base_url: document.getElementById('plex-url').value,