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

Remove unneeded contrib.appengine exceptions #533

Merged
merged 1 commit into from
Jul 12, 2016
Merged
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
29 changes: 11 additions & 18 deletions oauth2client/contrib/appengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,6 @@ def _safe_html(s):
return cgi.escape(s, quote=1).replace("'", ''')


class InvalidClientSecretsError(Exception):
"""The client_secrets.json file is malformed or missing required fields."""


class InvalidXsrfTokenError(Exception):
"""The XSRF token is invalid or expired."""


class SiteXsrfSecretKey(db.Model):
"""Storage for the sites XSRF secret key.

Expand Down Expand Up @@ -475,18 +467,15 @@ def _parse_state_value(state, user):
state: string, The value of the state parameter.
user: google.appengine.api.users.User, The current user.

Raises:
InvalidXsrfTokenError: if the XSRF token is invalid.

Returns:
The redirect URI.
The redirect URI, or None if XSRF token is not valid.
"""
uri, token = state.rsplit(':', 1)
if not xsrfutil.validate_token(xsrf_secret_key(), token, user.user_id(),
action_id=uri):
raise InvalidXsrfTokenError()

return uri
if xsrfutil.validate_token(xsrf_secret_key(), token, user.user_id(),
action_id=uri):
return uri
else:
return None


class OAuth2Decorator(object):
Expand Down Expand Up @@ -814,6 +803,10 @@ def get(self):
user=user).put(credentials)
redirect_uri = _parse_state_value(
str(self.request.get('state')), user)
if redirect_uri is None:
self.response.out.write(
'The authorization request failed')
return

if (decorator._token_response_param and
credentials.token_response):
Expand Down Expand Up @@ -884,7 +877,7 @@ def __init__(self, filename, scope, message=None, cache=None, **kwargs):
cache=cache)
if client_type not in (clientsecrets.TYPE_WEB,
clientsecrets.TYPE_INSTALLED):
raise InvalidClientSecretsError(
raise clientsecrets.InvalidClientSecretsError(
"OAuth2Decorator doesn't support this OAuth 2.0 flow.")

constructor_kwargs = dict(kwargs)
Expand Down
8 changes: 3 additions & 5 deletions tests/contrib/test_appengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@
from oauth2client.contrib.appengine import CredentialsNDBModel
from oauth2client.contrib.appengine import CredentialsProperty
from oauth2client.contrib.appengine import FlowProperty
from oauth2client.contrib.appengine import (
InvalidClientSecretsError as AppEngineInvalidClientSecretsError)
from oauth2client.contrib.appengine import OAuth2Decorator
from oauth2client.contrib.appengine import oauth2decorator_from_clientsecrets
from oauth2client.contrib.appengine import OAuth2DecoratorFromClientSecrets
Expand Down Expand Up @@ -921,7 +919,7 @@ def test_decorator_from_client_secrets_bad_type(self):
'oauth2client.contrib.appengine.clientsecrets.loadfile')
with loadfile_patch as loadfile_mock:
loadfile_mock.return_value = ('badtype', None)
with self.assertRaises(AppEngineInvalidClientSecretsError):
with self.assertRaises(InvalidClientSecretsError):
OAuth2DecoratorFromClientSecrets(
'doesntmatter.json',
scope=['foo_scope', 'bar_scope'])
Expand Down Expand Up @@ -1077,5 +1075,5 @@ def test_build_and_parse_state(self):
self.assertEqual(
'https://example.org',
appengine._parse_state_value(state, UserMock()))
with self.assertRaises(appengine.InvalidXsrfTokenError):
appengine._parse_state_value(state[1:], UserMock())
redirect_uri = appengine._parse_state_value(state[1:], UserMock())
self.assertIsNone(redirect_uri)