[GH-ISSUE #495] How to terminate token process if user exits authentication page? #295

Closed
opened 2026-02-27 23:21:51 +03:00 by kerem · 7 comments
Owner

Originally created by @StephenChou on GitHub (May 20, 2020).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/495

So in my web app I'm trying to account for the possibility that a user exits the Spotify authentication page without authenticating. How do I terminate the process? I have an "if token ... else return false" statement for the token but it doesn't seem to get there, it just stays running.

Originally created by @StephenChou on GitHub (May 20, 2020). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/495 So in my web app I'm trying to account for the possibility that a user exits the Spotify authentication page without authenticating. How do I terminate the process? I have an "if token ... else return false" statement for the token but it doesn't seem to get there, it just stays running.
kerem 2026-02-27 23:21:51 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@ysinjab commented on GitHub (May 27, 2020):

Assuming you are using authorization code: the user is unauthorized until he login & and give your application the authorization to access the scopes. https://tools.ietf.org/html/rfc6749#section-1.3.1

<!-- gh-comment-id:634677265 --> @ysinjab commented on GitHub (May 27, 2020): Assuming you are using authorization code: the user is **unauthorized** until he **login** & and **give** your application the **authorization** to access the scopes. https://tools.ietf.org/html/rfc6749#section-1.3.1
Author
Owner

@stephanebruckert commented on GitHub (May 30, 2020):

@stephenchou indeed the default is that if you do the following it will prompt and block if the spotipy authentication window is closed:

auth_manager = spotipy.oauth2.SpotifyOAuth()
spotify = spotipy.Spotify(auth_manager=auth_manager)

spotify.me()

To prevent prompting what you want to do is call auth_manager.get_access_token(code) before calling spotify.me(). A good example that does this is the API example https://github.com/plamere/spotipy/blob/master/examples/app.py where each action is separate and therefore won't block the main process

<!-- gh-comment-id:636353271 --> @stephanebruckert commented on GitHub (May 30, 2020): @stephenchou indeed the default is that if you do the following it will prompt and block if the spotipy authentication window is closed: ``` auth_manager = spotipy.oauth2.SpotifyOAuth() spotify = spotipy.Spotify(auth_manager=auth_manager) spotify.me() ``` To prevent prompting what you want to do is call `auth_manager.get_access_token(code)` before calling `spotify.me()`. A good example that does this is the API example https://github.com/plamere/spotipy/blob/master/examples/app.py where each action is separate and therefore won't block the main process
Author
Owner

@StephenChou commented on GitHub (May 30, 2020):

@stephanebruckert Thanks for your response. I forgot to mention that I'm using the "prompt_for_user_token" function and it doesn't seem to be returning false when I exit the authorization webpage without authenticating. Should I avoid using that then?

<!-- gh-comment-id:636362241 --> @StephenChou commented on GitHub (May 30, 2020): @stephanebruckert Thanks for your response. I forgot to mention that I'm using the "prompt_for_user_token" function and it doesn't seem to be returning false when I exit the authorization webpage without authenticating. Should I avoid using that then?
Author
Owner

@stephanebruckert commented on GitHub (May 31, 2020):

@StephenChou do you mean that it behaves as expected with auth_manager but doesn't with prompt_for_user_token?

<!-- gh-comment-id:636439821 --> @stephanebruckert commented on GitHub (May 31, 2020): @StephenChou do you mean that it behaves as expected with `auth_manager` but doesn't with `prompt_for_user_token`?
Author
Owner

@StephenChou commented on GitHub (May 31, 2020):

@stephanebruckert Haven't tried auth manager yet, was hoping that I could possibly still use prompt_for_user_token, which doesn't seem to be hitting my false condition when I exit the authentication page. I guess I should probably try auth_manager then.

<!-- gh-comment-id:636474741 --> @StephenChou commented on GitHub (May 31, 2020): @stephanebruckert Haven't tried auth manager yet, was hoping that I could possibly still use prompt_for_user_token, which doesn't seem to be hitting my false condition when I exit the authentication page. I guess I should probably try auth_manager then.
Author
Owner

@stephanebruckert commented on GitHub (May 31, 2020):

Yeah I doubt it will be any different with the auth_manager. If the authentication page is closed, I can't see how the python app could know about it because nothing is sent to the redirect URI. If this is a problem for you I really suggest you do something similar to the API example

<!-- gh-comment-id:636481581 --> @stephanebruckert commented on GitHub (May 31, 2020): Yeah I doubt it will be any different with the auth_manager. If the authentication page is closed, I can't see how the python app could know about it because nothing is sent to the redirect URI. If this is a problem for you I really suggest you do something similar to the API example
Author
Owner

@stephanebruckert commented on GitHub (Jun 14, 2020):

Your solution is here, closing

<!-- gh-comment-id:643794543 --> @stephanebruckert commented on GitHub (Jun 14, 2020): Your solution is [here](https://github.com/plamere/spotipy/blob/master/FAQ.md#how-to-use-spotipy-in-an-api), closing
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#295
No description provided.