Skip to content
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
10 changes: 6 additions & 4 deletions oauthlib/oauth2/rfc6749/parameters.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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