From 3e244f2be7e8372109ac29bf84b11f7aadc4733b Mon Sep 17 00:00:00 2001 From: aldbr Date: Fri, 2 Feb 2024 11:27:47 +0100 Subject: [PATCH] fix: correctly set the duration of tokens in cache --- src/DIRAC/FrameworkSystem/Client/TokenManagerClient.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/DIRAC/FrameworkSystem/Client/TokenManagerClient.py b/src/DIRAC/FrameworkSystem/Client/TokenManagerClient.py index 2157ef970ea..74324bcbddc 100644 --- a/src/DIRAC/FrameworkSystem/Client/TokenManagerClient.py +++ b/src/DIRAC/FrameworkSystem/Client/TokenManagerClient.py @@ -1,6 +1,8 @@ """ The TokenManagerClient is a class representing the client of the DIRAC :py:mod:`TokenManager ` service. """ +import time + from DIRAC import S_OK, S_ERROR from DIRAC.Core.Utilities import ThreadSafe from DIRAC.Core.Utilities.DictCache import DictCache @@ -70,7 +72,7 @@ def getToken( if result["OK"]: token = OAuth2Token(dict(result["Value"])) - # Get the date at which the token will expire + # Get the date at which the token will expire (it is expressed as a Unix timestamp) # If the refresh token is present, we use it as we can easily generate an access token from it duration = token.get_claim("exp", "access_token") or DEFAULT_AT_EXPIRATION_TIME if token.get("refresh_token"): @@ -78,7 +80,7 @@ def getToken( self.__tokensCache.add( cachedKey, - duration, + duration - time.time(), token, )