Skip to content

Commit

Permalink
Add param state in authorize method.
Browse files Browse the repository at this point in the history
  • Loading branch information
lepture committed Dec 10, 2013
1 parent 6202188 commit 21f5c3e
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions flask_oauthlib/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,10 @@ def authorize(self, callback=None, state=None):
Returns a redirect response to the remote authorization URL with
the signed callback given.
:param state: an optional value to embed in the OAuth request. Use this
if you want to pass around application state (e.g. CSRF tokens).
:param callback: a redirect url for the callback
:param state: an optional value to embed in the OAuth request.
Use this if you want to pass around application
state (e.g. CSRF tokens).
"""
if self.request_token_url:
token = self.generate_request_token(callback)[0]
Expand All @@ -466,11 +468,15 @@ def authorize(self, callback=None, state=None):
scope = _encode(scope, self.encoding)

if 'state' in params:
state = params.pop('state')
if callable(state):
state = state()
else:
state = None
if not state:
state = params.pop('state')
else:
# remove state in params
params.pop('state')

if callable(state):
# state can be function for generate a random string
state = state()

session['%s_oauthredir' % self.name] = callback
url = client.prepare_request_uri(
Expand Down

0 comments on commit 21f5c3e

Please # to comment.