Skip to content
This repository has been archived by the owner on Jan 18, 2025. It is now read-only.

Commit

Permalink
Third pass comments (to be squashed)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bill Prin committed Jul 21, 2016
1 parent e281441 commit 19df713
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 18 deletions.
13 changes: 8 additions & 5 deletions oauth2client/contrib/django_util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def _get_storage_model():
credentials into an existing Django user system.
Returns:
A tuple containing three strings, or None. If
A tuple containing three strings, or None. If
``GOOGLE_OAUTH2_STORAGE_MODEL`` is configured, the tuple
will contain the fully qualifed path of the `django.db.model`,
the name of the ``django.contrib.auth.models.User`` field on the
Expand Down Expand Up @@ -383,8 +383,10 @@ def get_storage(request):


def _redirect_with_params(url_name, *args, **kwargs):
"""Helper method to create a redirect response that uses GET URL
parameters.
"""Helper method to create a redirect response with URL params.
This builds a redirect string that converts kwargs into a
query string.
Args:
url_name: The name of the url to redirect to.
Expand Down Expand Up @@ -424,9 +426,10 @@ def __init__(self, request, scopes=None, return_url=None):
"""
self.request = request
self.return_url = return_url or request.get_full_path()
self._scopes = set(oauth2_settings.scopes)
if scopes:
self._scopes |= set(scopes)
self._scopes = set(oauth2_settings.scopes) | set(scopes)
else:
self._scopes = set(oauth2_settings.scopes)

def get_authorize_redirect(self):
"""Creates a URl to start the OAuth2 authorization flow."""
Expand Down
21 changes: 11 additions & 10 deletions oauth2client/contrib/django_util/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def requires_default_scopes(request):
Args:
decorated_function: View function to decorate, must have the Django
request object as the first argument.
scopes: Scopes to require, will default
scopes: Scopes to require, will default.
decorator_kwargs: Can include ``return_url`` to specify the URL to
return to after OAuth2 authorization is complete.
Expand All @@ -72,10 +72,11 @@ def curry_wrapper(wrapped_function):
def required_wrapper(request, *args, **kwargs):
if not (django_util.oauth2_settings.storage_model is None or
request.user.is_authenticated()):
return shortcuts.redirect(
'{0}?next={1}'.format(
django.conf.settings.LOGIN_URL, parse.quote(
request.path)))
redirect_str = '{0}?next={1}'.format(
django.conf.settings.LOGIN_URL,
parse.quote(request.path))
return shortcuts.redirect(redirect_str)

return_url = decorator_kwargs.pop('return_url',
request.get_full_path())
user_oauth = django_util.UserOAuth2(request, scopes, return_url)
Expand Down Expand Up @@ -110,21 +111,21 @@ def optional_oauth2(request):
# this could be passed into a view
# request.oauth.http is also initialized
return HttpResponse("User email: {0}".format(
request.oauth.credentials.id_token['email'
request.oauth.credentials.id_token['email'])
else:
return HttpResponse('Here is an OAuth Authorize link:
<a href="{0}">Authorize</a>'.format(
request.oauth.get_authorize_redirect()))
Args:
decorated_function: View function to decorate
scopes: Scopes to require, will default
decorated_function: View function to decorate.
scopes: Scopes to require, will default.
decorator_kwargs: Can include ``return_url`` to specify the URL to
return to after OAuth2 authorization is complete
return to after OAuth2 authorization is complete.
Returns:
The decorated view function
The decorated view function.
"""
def curry_wrapper(wrapped_function):
@wraps(wrapped_function)
Expand Down
2 changes: 1 addition & 1 deletion oauth2client/contrib/django_util/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""This module contains classes used for the Django ORM storage"""
"""Contains classes used for the Django ORM storage."""

import base64
import pickle
Expand Down
2 changes: 2 additions & 0 deletions oauth2client/contrib/xsrfutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,5 @@ def validate_token(key, token, user_id, action_id="", current_time=None):
for x, y in zip(bytearray(token), bytearray(expected_token)):
different |= x ^ y
return not different


2 changes: 1 addition & 1 deletion tests/contrib/django_util/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def test_view(request):
return http.HttpResponse("test") # pragma: NO COVER

response = test_view(request)
self.assertEquals(
self.assertEqual(
response.status_code, django.http.HttpResponseRedirect.status_code)

@mock.patch('oauth2client.contrib.dictionary_storage.OAuth2Credentials')
Expand Down
2 changes: 1 addition & 1 deletion tests/contrib/django_util/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def test_error_returns_bad_request(self):
})
response = views.oauth2_callback(request)
self.assertIsInstance(response, http.HttpResponseBadRequest)
self.assertTrue(b'Authorization failed' in response.content)
self.assertIn(b'Authorization failed', response.content)

def test_no_session(self):
request = self.factory.get('oauth2/oauth2callback', data={
Expand Down

0 comments on commit 19df713

Please sign in to comment.