Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for OAuth2 state parameter #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions flask_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,16 @@ def free_request_token(self):
session.pop(self.name + '_oauthtok', None)
session.pop(self.name + '_oauthredir', None)

def authorize(self, callback=None):
def authorize(self, callback=None, state=None):
"""Returns a redirect response to the remote authorization URL with
the signed callback given. The callback must be `None` in which
case the application will most likely switch to PIN based authentication
or use a remotely stored callback URL. Alternatively it's an URL
on the system that has to be decorated as :meth:`authorized_handler`.

: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,
URLs, etc.)
"""
if self.request_token_url:
token = self.generate_request_token(callback)[0]
Expand All @@ -339,7 +343,8 @@ def authorize(self, callback=None):
params = dict(self.request_token_params)
params['redirect_uri'] = callback
params['client_id'] = self.consumer_key
params['response_type'] = 'code'
if state:
params['state'] = state
session[self.name + '_oauthredir'] = callback
url = add_query(self.expand_url(self.authorize_url), params)

Expand Down