From 6ef9d4f61799affe145e3331d72f1cb6026d1432 Mon Sep 17 00:00:00 2001 From: Simon Robinson Date: Fri, 15 Mar 2024 08:25:32 +0000 Subject: [PATCH] Make sure token `expires_in` values are integers Closes #237 --- emailproxy.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/emailproxy.py b/emailproxy.py index f40c100..c054020 100644 --- a/emailproxy.py +++ b/emailproxy.py @@ -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 @@ -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)