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.
This commit is contained in:
Michael Birtwell 2017-01-07 13:13:35 +00:00
parent bf219eb264
commit 5aadb284ff
1 changed files with 5 additions and 3 deletions

View File

@ -162,7 +162,7 @@ class SpotifyOAuth(object):
now = int(time.time()) now = int(time.time())
return token_info['expires_at'] < now 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 """ Gets the URL to use to authorize this app
""" """
payload = {'client_id': self.client_id, payload = {'client_id': self.client_id,
@ -170,8 +170,10 @@ class SpotifyOAuth(object):
'redirect_uri': self.redirect_uri} 'redirect_uri': self.redirect_uri}
if self.scope: if self.scope:
payload['scope'] = self.scope payload['scope'] = self.scope
if self.state: if state is None:
payload['state'] = self.state state = self.state
if state is not None:
payload['state'] = state
urlparams = urllibparse.urlencode(payload) urlparams = urllibparse.urlencode(payload)