Skip to content

Commit eed87c4

Browse files
authored
Merge pull request #20821 from jdavcs/24.2_refresh_token
[24.2] Fix token refresh bug (cilogon)
2 parents 4ea216f + 7041b6b commit eed87c4

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lib/galaxy/authnz/custos_authnz.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,19 @@ 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
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.warning("Refresh token cannot be decoded. Galaxy does not support non-decodable refresh tokens.")
136+
# If the refresh token is non-decodable, we do not use it because we cannot reliably determine its expiration date. See discussion in https://github.com/galaxyproject/galaxy/pull/20821
130137
return False
138+
131139
oauth2_session = self._create_oauth2_session()
132140
token_endpoint = self.config.token_endpoint
133141
if self.config.iam_client_secret:

0 commit comments

Comments
 (0)