[GH-ISSUE #1073] Headless auth? #631

Closed
opened 2026-02-28 00:00:24 +03:00 by kerem · 5 comments
Owner

Originally created by @dougthor42 on GitHub (Feb 20, 2024).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1073

Is your feature request related to a problem? Please describe.
I run this using a headless host / one without access to a web browser (eg: I'm SSH'd into a different machine).

Describe the solution you'd like
When authenticating using the Authorization Code Flow, print the auth url in the terminal. This allows the user to copy it into a browser manually. Then wait for the user to paste the secret into the terminal.

Describe alternatives you've considered
For now I just have to copy my code to a non-headless (headfull?) machine and run it from there.

Additional context
Headless auth was also mentioned in the 3.0 ideas issue https://github.com/spotipy-dev/spotipy/issues/652#issuecomment-894581817

Originally created by @dougthor42 on GitHub (Feb 20, 2024). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1073 **Is your feature request related to a problem? Please describe.** I run this using a headless host / one without access to a web browser (eg: I'm SSH'd into a different machine). **Describe the solution you'd like** When authenticating using the Authorization Code Flow, print the auth url in the terminal. This allows the user to copy it into a browser manually. Then wait for the user to paste the secret into the terminal. **Describe alternatives you've considered** For now I just have to copy my code to a non-headless (headfull?) machine and run it from there. **Additional context** Headless auth was also mentioned in the 3.0 ideas issue https://github.com/spotipy-dev/spotipy/issues/652#issuecomment-894581817
kerem 2026-02-28 00:00:24 +03:00
Author
Owner

@aymather commented on GitHub (Mar 5, 2024):

@dougthor42 instead of doing a workaround just for the authentication flow in your headless environment, perform the auth flow once locally (i.e. in an environment where you can get redirected to a browser) which will create a .cache file for you. Then just move that file to your headless environment (i.e. the place you're ssh'ed into) and it should work without needing to authenticate every time because it can pull the token data from your .cache file.

<!-- gh-comment-id:1979806665 --> @aymather commented on GitHub (Mar 5, 2024): @dougthor42 instead of doing a workaround just for the authentication flow in your headless environment, perform the auth flow once locally (i.e. in an environment where you _can_ get redirected to a browser) which will create a `.cache` file for you. Then just move that file to your headless environment (i.e. the place you're ssh'ed into) and it should work without needing to authenticate every time because it can pull the token data from your `.cache` file.
Author
Owner

@twointum commented on GitHub (Mar 12, 2024):

@dougthor42 instead of doing a workaround just for the authentication flow in your headless environment, perform the auth flow once locally (i.e. in an environment where you can get redirected to a browser) which will create a .cache file for you. Then just move that file to your headless environment (i.e. the place you're ssh'ed into) and it should work without needing to authenticate every time because it can pull the token data from your .cache file.

Hi! Where exactly does that .cache file go? I have the same issue and it's driving me crazy. My remote server is running a python virtual environment that is running Apache Airflow.

<!-- gh-comment-id:1990908456 --> @twointum commented on GitHub (Mar 12, 2024): > @dougthor42 instead of doing a workaround just for the authentication flow in your headless environment, perform the auth flow once locally (i.e. in an environment where you _can_ get redirected to a browser) which will create a `.cache` file for you. Then just move that file to your headless environment (i.e. the place you're ssh'ed into) and it should work without needing to authenticate every time because it can pull the token data from your `.cache` file. Hi! Where exactly does that .cache file go? I have the same issue and it's driving me crazy. My remote server is running a python virtual environment that is running Apache Airflow.
Author
Owner

@dougthor42 commented on GitHub (Mar 12, 2024):

Looks like the same dir as the file being run. For example, in https://github.com/dougthor42/spotify-favorites-fixer:

$ dthor@odin /c/dev/spotify-favorites-fixer (master): tree -L 1
spotify-favorites-fixer/
├── .cache    # <-- Here it is!
├── ...
├── .venv/
├── ...
├── fix_spotify_favorites.py
├── ...
└── test_fix_spotify_favorites.py

The file itself has this pattern:

{
  "access_token": "REDACTED",
  "token_type": "Bearer",
  "expires_in": 3600,
  "refresh_token": "REDACTED",
  "scope": "user-library-modify user-library-read",
  "expires_at": 1708462345
}
<!-- gh-comment-id:1992285052 --> @dougthor42 commented on GitHub (Mar 12, 2024): Looks like the same dir as the file being run. For example, in https://github.com/dougthor42/spotify-favorites-fixer: ```console $ dthor@odin /c/dev/spotify-favorites-fixer (master): tree -L 1 spotify-favorites-fixer/ ├── .cache # <-- Here it is! ├── ... ├── .venv/ ├── ... ├── fix_spotify_favorites.py ├── ... └── test_fix_spotify_favorites.py ``` The file itself has this pattern: ```json { "access_token": "REDACTED", "token_type": "Bearer", "expires_in": 3600, "refresh_token": "REDACTED", "scope": "user-library-modify user-library-read", "expires_at": 1708462345 } ```
Author
Owner

@dieser-niko commented on GitHub (Apr 30, 2024):

Hi there, sorry for the late reply. Most auth managers in spotipy have an open_browser parameter, you can use it like this: spotipy/examples/headless.py

<!-- gh-comment-id:2085498258 --> @dieser-niko commented on GitHub (Apr 30, 2024): Hi there, sorry for the late reply. Most auth managers in spotipy have an `open_browser` parameter, you can use it like this: [spotipy/examples/headless.py](https://github.com/spotipy-dev/spotipy/blob/master/examples/headless.py)
Author
Owner

@dieser-niko commented on GitHub (May 21, 2024):

Closing as this issue seems to be resolved.

<!-- gh-comment-id:2123446894 --> @dieser-niko commented on GitHub (May 21, 2024): Closing as this issue seems to be resolved.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotipy#631
No description provided.