Skip to content

Commit

Permalink
Handle null value in expires_in field in JSON handler (#675)
Browse files Browse the repository at this point in the history
Handle null value in expires_in field in JSON handler
  • Loading branch information
JonathanHuot committed Jul 4, 2019
2 parents a44e080 + 3bca3b3 commit d7b90fc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion oauthlib/oauth2/rfc6749/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,10 @@ def parse_token_response(body, scope=None):
params['scope'] = scope_to_list(params['scope'])

if 'expires_in' in params:
params['expires_at'] = time.time() + int(params['expires_in'])
if params['expires_in'] is None:
params.pop('expires_in')
else:
params['expires_at'] = time.time() + int(params['expires_in'])

params = OAuth2Token(params, old_scope=scope)
validate_token_parameters(params)
Expand Down
18 changes: 18 additions & 0 deletions tests/oauth2/rfc6749/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ def setUp(self):
' "expires_in": 3600,'
' "refresh_token": "tGzv3JOkF0XG5Qx2TlKWIA",'
' "example_parameter": "example_value" }')
json_response_noexpire = ('{ "access_token": "2YotnFZFEjr1zCsicMWpAA",'
' "token_type": "example",'
' "refresh_token": "tGzv3JOkF0XG5Qx2TlKWIA",'
' "example_parameter": "example_value"}')
json_response_expirenull = ('{ "access_token": "2YotnFZFEjr1zCsicMWpAA",'
' "token_type": "example",'
' "expires_in": null,'
' "refresh_token": "tGzv3JOkF0XG5Qx2TlKWIA",'
' "example_parameter": "example_value"}')

json_custom_error = '{ "error": "incorrect_client_credentials" }'
json_error = '{ "error": "access_denied" }'
Expand Down Expand Up @@ -136,6 +145,13 @@ def setUp(self):
'example_parameter': 'example_value'
}

json_noexpire_dict = {
'access_token': '2YotnFZFEjr1zCsicMWpAA',
'token_type': 'example',
'refresh_token': 'tGzv3JOkF0XG5Qx2TlKWIA',
'example_parameter': 'example_value'
}

json_notype_dict = {
'access_token': '2YotnFZFEjr1zCsicMWpAA',
'expires_in': 3600,
Expand Down Expand Up @@ -212,6 +228,8 @@ def test_json_token_response(self):

self.assertEqual(parse_token_response(self.json_response_noscope,
scope=['all', 'the', 'scopes']), self.json_noscope_dict)
self.assertEqual(parse_token_response(self.json_response_noexpire), self.json_noexpire_dict)
self.assertEqual(parse_token_response(self.json_response_expirenull), self.json_noexpire_dict)

scope_changes_recorded = []
def record_scope_change(sender, message, old, new):
Expand Down

0 comments on commit d7b90fc

Please sign in to comment.