Skip to content

Commit

Permalink
Fix handling of jwt refreshes
Browse files Browse the repository at this point in the history
  • Loading branch information
bennybp committed Oct 26, 2023
1 parent 23b51cb commit be08db0
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions qcportal/qcportal/client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,11 @@ def _refresh_JWT_token(self) -> None:
)
self._jwt_access_exp = decoded_access_token["exp"]

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

def _request(
Expand All @@ -294,14 +298,14 @@ def _request(
allow_retries: bool = True,
) -> requests.Response:

# If JWT token is expired, automatically renew it
if self._jwt_access_exp and self._jwt_access_exp < time.time():
self._refresh_JWT_token()

# If refresh token has expired, log in again
if self._jwt_refresh_exp and self._jwt_refresh_exp < time.time():
self._get_JWT_token()

# If only the JWT token is expired, automatically renew it
if self._jwt_access_exp and self._jwt_access_exp < time.time():
self._refresh_JWT_token()

full_uri = self.address + endpoint

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

0 comments on commit be08db0

Please sign in to comment.