mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-04-27 00:25:54 +03:00
[GH-ISSUE #262] Authorization Without Pasting Into Console #142
Labels
No labels
api-bug
bug
dependencies
documentation
duplicate
enhancement
external-ide
headless-mode
implicit-grant-flow
invalid
missing-endpoint
pr-welcome
private-api
pull-request
question
spotipy3
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/spotipy#142
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @astralmedia on GitHub (Feb 23, 2018).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/262
Hey, I am trying to use the authorization flow, but it is not possible in production to have each user paste their url into the console.
How do I go about authenticating a user for a web app? I am using django and want to do the auth stuff in my code, and deal with their response url on my own.
Thank you for any insight.
@gawaineo commented on GitHub (Mar 1, 2018):
@astralmedia You'll have to automate that part on the backend by doing the following:
usernameandpasswordNote: You will most likely need to use a headless browser such as Selenium webdriver in combination with PhantomJS. If the headless browser doesn't work out, the other option is to use a virtual display such as Xvfb or PyVirtualDisplay (http://pyvirtualdisplay.readthedocs.io/en/latest/) with a webdriver.
I recommend starting with the headless browser approach first.
Headless browser source: https://duo.com/blog/driving-headless-chrome-with-python
Don't worry, it's possible to get this working, I've done it before for project I was working on.
Source: https://developer.spotify.com/web-api/authorization-guide/#authorization-code-flow
@zdhoward commented on GitHub (Feb 4, 2020):
I would recommend something a little more lightweight than django.
I chose to use cherrypy for this.
You can see the code I use to do this and I will detail a couple steps here for you.
I use the wait_for_http_callback() to host a lightweight http server and awaiting and saving 1 request
https://github.com/zdhoward/Spotify-Genre-Playlist-Generator/blob/master/callbacks.py
Then I use the visit_url() function to use selenium rather than webbrowser to open the link headlessly while still following all the redirects.
Then you need to use a function similar to the prompt_user_for_auth_token() that doesn't output so much junk, launches the web server and makes the request using selenium.
You can see my modified function called get_user_token() here:
https://github.com/zdhoward/Spotify-Genre-Playlist-Generator/blob/master/main.py
I also had to add "from spotipy import oauth2" in the same file as the get_user_token() function.
I hope this gives you a good start on it!
@stephanebruckert commented on GitHub (Feb 9, 2020):
Hi,
This is highly disrecommended because you are not supposed to ask for the users Spotify passwords.
Instead you should redirect each user to the spotify authorization URL that will take care of verifying the password.
For now you can find some quick directions here https://github.com/plamere/spotipy/issues/287#issuecomment-576896586 but we still need to add a proper example in the doc
@stephanebruckert commented on GitHub (Feb 9, 2020):
Closing, please refer to https://github.com/plamere/spotipy/issues/287