Skip to content

Commit de33af2

Browse files
authored
Merge pull request #783 from MolSSI/jwt_fix
Fix handling of JWT refresh tokens
2 parents 23b51cb + be08db0 commit de33af2

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

qcportal/qcportal/client_base.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,11 @@ def _refresh_JWT_token(self) -> None:
280280
)
281281
self._jwt_access_exp = decoded_access_token["exp"]
282282

283-
else: # shouldn't happen unless user is blacklisted
283+
elif ret.status_code == 401 and "Token has expired" in ret.json()["msg"]:
284+
# If the refresh token has expired, try to log in again
285+
self._get_JWT_token()
286+
else: # shouldn't happen unless user is blacklisted or something
287+
print(ret, ret.text)
284288
raise ConnectionRefusedError("Unable to refresh JWT authorization token! This is a server issue!!")
285289

286290
def _request(
@@ -294,14 +298,14 @@ def _request(
294298
allow_retries: bool = True,
295299
) -> requests.Response:
296300

297-
# If JWT token is expired, automatically renew it
298-
if self._jwt_access_exp and self._jwt_access_exp < time.time():
299-
self._refresh_JWT_token()
300-
301301
# If refresh token has expired, log in again
302302
if self._jwt_refresh_exp and self._jwt_refresh_exp < time.time():
303303
self._get_JWT_token()
304304

305+
# If only the JWT token is expired, automatically renew it
306+
if self._jwt_access_exp and self._jwt_access_exp < time.time():
307+
self._refresh_JWT_token()
308+
305309
full_uri = self.address + endpoint
306310

307311
req = requests.Request(method=method.upper(), url=full_uri, data=body, params=url_params)

0 commit comments

Comments
 (0)