diff options
author | Bill Prin <waprin@gmail.com> | 2016-09-16 15:50:17 -0700 |
---|---|---|
committer | Jon Wayne Parrott <jonwayne@google.com> | 2016-09-16 15:50:16 -0700 |
commit | 8a6e3b2a34561fb575ceecbb0f598347d47786e3 (patch) | |
tree | b2b69bcf4b7a7f5e5af13584038b98be2b6eddc8 /oauth2client | |
parent | 9f0618d53481a3afe2d0cf232131ba21dcf583de (diff) | |
download | oauth2client-8a6e3b2a34561fb575ceecbb0f598347d47786e3.tar.gz |
Fix django authorization redirect by correctly checking validity of credentials (#651)
Diffstat (limited to 'oauth2client')
-rw-r--r-- | oauth2client/contrib/django_util/views.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/oauth2client/contrib/django_util/views.py b/oauth2client/contrib/django_util/views.py index 4858f20..009b544 100644 --- a/oauth2client/contrib/django_util/views.py +++ b/oauth2client/contrib/django_util/views.py @@ -170,7 +170,10 @@ def oauth2_authorize(request): A redirect to Google OAuth2 Authorization. """ return_url = request.GET.get('return_url', None) + if not return_url: + return_url = request.META.get('HTTP_REFERER', '/') + scopes = request.GET.getlist('scopes', django_util.oauth2_settings.scopes) # Model storage (but not session storage) requires a logged in user if django_util.oauth2_settings.storage_model: if not request.user.is_authenticated(): @@ -178,13 +181,11 @@ def oauth2_authorize(request): settings.LOGIN_URL, parse.quote(request.get_full_path()))) # This checks for the case where we ended up here because of a logged # out user but we had credentials for it in the first place - elif get_storage(request).get() is not None: - return redirect(return_url) + else: + user_oauth = django_util.UserOAuth2(request, scopes, return_url) + if user_oauth.has_credentials(): + return redirect(return_url) - scopes = request.GET.getlist('scopes', django_util.oauth2_settings.scopes) - - if not return_url: - return_url = request.META.get('HTTP_REFERER', '/') flow = _make_flow(request=request, scopes=scopes, return_url=return_url) auth_url = flow.step1_get_authorize_url() return shortcuts.redirect(auth_url) |