Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to do auth manually on headless server #88

Merged
merged 1 commit into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add option to do auth manually on headless server
  • Loading branch information
timrae committed Oct 14, 2024
commit 0bc17859db8c0495412aba12b571ab081ff70c0b
1 change: 1 addition & 0 deletions example_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ spotify:
client_secret: your_client_secret
username: your_spotify_username
redirect_uri: http://localhost:8888/callback
open_browser: True # Set to False if using a headless server environment


# uncomment this block if you want to only sync specific playlist IDs
Expand Down
11 changes: 6 additions & 5 deletions src/spotify_to_tidal/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@

def open_spotify_session(config) -> spotipy.Spotify:
credentials_manager = spotipy.SpotifyOAuth(username=config['username'],
scope=SPOTIFY_SCOPES,
client_id=config['client_id'],
client_secret=config['client_secret'],
redirect_uri=config['redirect_uri'],
requests_timeout=2)
scope=SPOTIFY_SCOPES,
client_id=config['client_id'],
client_secret=config['client_secret'],
redirect_uri=config['redirect_uri'],
requests_timeout=2,
open_browser=config.get('open_browser', True))
try:
credentials_manager.get_access_token(as_dict=False)
except spotipy.SpotifyOauthError:
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def test_open_spotify_session(mocker):
"client_id": "test_client_id",
"client_secret": "test_client_secret",
"redirect_uri": "http://localhost/",
"open_browser": True,
}

# Create a mock SpotifyOAuth instance
Expand All @@ -41,6 +42,7 @@ def test_open_spotify_session(mocker):
client_secret="test_client_secret",
redirect_uri="http://localhost/",
requests_timeout=2,
open_browser=True,
)

# Assert that the Spotify instance was created
Expand Down