Skip to content

Commit 3b9f75c

Browse files
authored
Merge pull request #19411 from martenson/ignore-expired
avoid using custos refresh tokens which are expired
2 parents c51a049 + 6b390e5 commit 3b9f75c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/galaxy/authnz/custos_authnz.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,16 @@ def refresh(self, trans, custos_authnz_token):
117117
if custos_authnz_token is None:
118118
raise exceptions.AuthenticationFailed("cannot find authorized user while refreshing token")
119119
id_token_decoded = self._decode_token_no_signature(custos_authnz_token.id_token)
120-
# do not refresh tokens if they didn't reach their half lifetime
120+
# do not refresh tokens if the id_token didn't reach its half-life
121121
if int(id_token_decoded["iat"]) + int(id_token_decoded["exp"]) > 2 * int(time.time()):
122122
return False
123+
if not custos_authnz_token.refresh_token:
124+
return False
125+
refresh_token_decoded = self._decode_token_no_signature(custos_authnz_token.refresh_token)
126+
# do not attempt to use refresh token that is already expired
127+
if int(refresh_token_decoded["exp"]) > int(time.time()):
128+
# in the future we might want to log out the user here
129+
return False
123130
log.info(custos_authnz_token.access_token)
124131
oauth2_session = self._create_oauth2_session()
125132
token_endpoint = self.config.token_endpoint

0 commit comments

Comments
 (0)