From 5aadb284ff12155b76f95f7ecc5701b8ff063494 Mon Sep 17 00:00:00 2001 From: Michael Birtwell Date: Sat, 7 Jan 2017 13:13:35 +0000 Subject: [PATCH] Add support for setting state in get_authorise_url This allows for example putting a next page url in the state to be loaded after authorization completes. --- spotipy/oauth2.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spotipy/oauth2.py b/spotipy/oauth2.py index 0d30bd3..e0811e9 100644 --- a/spotipy/oauth2.py +++ b/spotipy/oauth2.py @@ -162,7 +162,7 @@ class SpotifyOAuth(object): now = int(time.time()) return token_info['expires_at'] < now - def get_authorize_url(self): + def get_authorize_url(self, state=None): """ Gets the URL to use to authorize this app """ payload = {'client_id': self.client_id, @@ -170,8 +170,10 @@ class SpotifyOAuth(object): 'redirect_uri': self.redirect_uri} if self.scope: payload['scope'] = self.scope - if self.state: - payload['state'] = self.state + if state is None: + state = self.state + if state is not None: + payload['state'] = state urlparams = urllibparse.urlencode(payload)