Skip to content

Commit b00bc3e

Browse files
committed
Check if refresh token is decodable before decoding it
1 parent f28450c commit b00bc3e

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

lib/galaxy/authnz/custos_authnz.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,17 @@ def refresh(self, trans, custos_authnz_token):
123123
return False
124124
if not custos_authnz_token.refresh_token:
125125
return False
126-
refresh_token_decoded = self._decode_token_no_signature(custos_authnz_token.refresh_token)
127-
# do not attempt to use refresh token that is already expired
128-
if int(refresh_token_decoded["exp"]) <= int(time.time()):
129-
# in the future we might want to log out the user here
130-
return False
126+
127+
# Try to extract expiration date from the refresh token. If expired, do not refresh token.
128+
try:
129+
refresh_token_decoded = self._decode_token_no_signature(custos_authnz_token.refresh_token)
130+
# do not attempt to use refresh token that is already expired
131+
if int(refresh_token_decoded["exp"]) <= int(time.time()):
132+
# in the future we might want to log out the user here
133+
return False
134+
except jwt.exceptions.DecodeError:
135+
log.error("Refresh token is non-decodable")
136+
131137
oauth2_session = self._create_oauth2_session()
132138
token_endpoint = self.config.token_endpoint
133139
if self.config.iam_client_secret:

0 commit comments

Comments
 (0)