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

parameters.py - Expanding Error Code Catching #767

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions oauthlib/oauth2/rfc6749/parameters.py
Expand Up @@ -261,8 +261,9 @@ def parse_authorization_code_response(uri, state=None):
if state and params.get('state', None) != state:
raise MismatchingStateError()

if 'error' in params:
raise_from_error(params.get('error'), params)
for key in params.keys():
if 'error' in key.lower():
raise_from_error(params.get(key), params)

if not 'code' in params:
raise MissingCodeError("Missing code parameter in response.")
Expand Down Expand Up @@ -428,8 +429,9 @@ def parse_token_response(body, scope=None):

def validate_token_parameters(params):
"""Ensures token presence, token type, expiration and scope in params."""
if 'error' in params:
raise_from_error(params.get('error'), params)
for key in params.keys():
if 'error' in key.lower():
raise_from_error(params.get(key), params)

if not 'access_token' in params:
raise MissingTokenError(description="Missing access token parameter.")
Expand Down
8 changes: 6 additions & 2 deletions tests/oauth2/rfc6749/test_parameters.py
Expand Up @@ -111,7 +111,10 @@ def setUp(self):
' "refresh_token": "tGzv3JOkF0XG5Qx2TlKWIA",'
' "example_parameter": "example_value"}')

json_custom_error = '{ "error": "incorrect_client_credentials" }'
json_custom_errors = ['{ "error": "incorrect_client_credentials" }',
'{ "Error": "incorrect_client_credentials" }',
'{ "errorCode": "incorrect_client_credentials" }',
'{ "ERROR": "incorrect_client_credentials" }']
json_error = '{ "error": "access_denied" }'

json_notoken = ('{ "token_type": "example",'
Expand Down Expand Up @@ -216,7 +219,8 @@ def test_implicit_token_response(self):
self.implicit_wrongstate, state=self.state)

def test_custom_json_error(self):
self.assertRaises(CustomOAuth2Error, parse_token_response, self.json_custom_error)
for custom_error in self.json_custom_errors:
self.assertRaises(CustomOAuth2Error, parse_token_response, custom_error)

def test_json_token_response(self):
"""Verify correct parameter parsing and validation for token responses. """
Expand Down