Skip to content

Commit

Permalink
Make sure token expires_in values are integers
Browse files Browse the repository at this point in the history
Closes #237
  • Loading branch information
simonrob committed Mar 15, 2024
1 parent 1686f09 commit 6ef9d4f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions emailproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
__author__ = 'Simon Robinson'
__copyright__ = 'Copyright (c) 2024 Simon Robinson'
__license__ = 'Apache 2.0'
__version__ = '2024-03-14' # ISO 8601 (YYYY-MM-DD)
__version__ = '2024-03-15' # ISO 8601 (YYYY-MM-DD)
__package_version__ = '.'.join([str(int(i)) for i in __version__.split('-')]) # for pyproject.toml usage only

import abc
Expand Down Expand Up @@ -1114,7 +1114,11 @@ def refresh_oauth2_access_token(token_url, client_id, client_secret, refresh_tok
response = urllib.request.urlopen(
urllib.request.Request(token_url, data=urllib.parse.urlencode(params).encode('utf-8'),
headers={'User-Agent': APP_NAME}), timeout=AUTHENTICATION_TIMEOUT).read()
return json.loads(response)
token = json.loads(response)
if 'expires_in' in token: # some servers return integer values as strings - fix expiry values (GitHub #237)
token['expires_in'] = int(token['expires_in'])
return token

except urllib.error.HTTPError as e:
e.message = json.loads(e.read())
Log.debug('Error refreshing access token - received invalid response:', e.message)
Expand Down

0 comments on commit 6ef9d4f

Please sign in to comment.