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

Support mobile/AJAX one-step authentication using a POST to the login callback. #147

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
README = CHANGES = ''

setup(name='velruse',
version='1.1.1',
version='1.1.1.1',
description=(
'Simplifying third-party authentication for web applications.'),
long_description=README + '\n\n' + CHANGES,
Expand Down
43 changes: 27 additions & 16 deletions velruse/providers/google_oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,29 +119,40 @@ def login(self, request):

def callback(self, request):
"""Process the google redirect"""
sess_state = request.session.pop('velruse.state', None)
req_state = request.GET.get('state')
if not sess_state or sess_state != req_state:
raise CSRFError(
'CSRF Validation check failed. Request state {req_state} is '
'not the same as session state {sess_state}'.format(
req_state=req_state,
sess_state=sess_state
# If the client already did login client-side, we can use a provided code for a one-step login
if request.method == 'POST':
code = request.POST.get('code')
if not code:
return AuthenticationDenied(reason='Missing authentication code',
provider_name=self.name,
provider_type=self.type)
redirect_uri = 'postmessage'
else:
sess_state = request.session.pop('velruse.state', None)
req_state = request.GET.get('state')
if not sess_state or sess_state != req_state:
raise CSRFError(
'CSRF Validation check failed. Request state {req_state} is '
'not the same as session state {sess_state}'.format(
req_state=req_state,
sess_state=sess_state
)
)
)
code = request.GET.get('code')
if not code:
reason = request.GET.get('error', 'No reason provided.')
return AuthenticationDenied(reason=reason,
provider_name=self.name,
provider_type=self.type)

code = request.GET.get('code')
if not code:
reason = request.GET.get('error', 'No reason provided.')
return AuthenticationDenied(reason=reason,
provider_name=self.name,
provider_type=self.type)
redirect_uri = request.route_url(self.callback_route)

# Now retrieve the access token with the code
r = requests.post(
'%s://%s/o/oauth2/token' % (self.protocol, self.domain),
dict(client_id=self.consumer_key,
client_secret=self.consumer_secret,
redirect_uri=request.route_url(self.callback_route),
redirect_uri=redirect_uri,
code=code,
grant_type='authorization_code'),
)
Expand Down