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

Headless auth? #1073

Closed
dougthor42 opened this issue Feb 20, 2024 · 5 comments
Closed

Headless auth? #1073

dougthor42 opened this issue Feb 20, 2024 · 5 comments

Comments

@dougthor42
Copy link

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 #652 (comment)

@aymather
Copy link

aymather commented 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.

@twointum
Copy link

@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.

@dougthor42
Copy link
Author

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
}

@dieser-niko
Copy link
Member

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

@dieser-niko
Copy link
Member

Closing as this issue seems to be resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants