Skip to content

Commit 2d5ab55

Browse files
authored
Merge pull request #7438 from aldbr/v8.0_FIX_TokenManagerClient-cachedTokens
[8.0] fix: correctly set the duration of tokens in cache
2 parents 74fe559 + 3e244f2 commit 2d5ab55

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/DIRAC/FrameworkSystem/Client/TokenManagerClient.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
""" The TokenManagerClient is a class representing the client of the DIRAC
22
:py:mod:`TokenManager <DIRAC.FrameworkSystem.Service.TokenManagerHandler>` service.
33
"""
4+
import time
5+
46
from DIRAC import S_OK, S_ERROR
57
from DIRAC.Core.Utilities import ThreadSafe
68
from DIRAC.Core.Utilities.DictCache import DictCache
@@ -70,15 +72,15 @@ def getToken(
7072
if result["OK"]:
7173
token = OAuth2Token(dict(result["Value"]))
7274

73-
# Get the date at which the token will expire
75+
# Get the date at which the token will expire (it is expressed as a Unix timestamp)
7476
# If the refresh token is present, we use it as we can easily generate an access token from it
7577
duration = token.get_claim("exp", "access_token") or DEFAULT_AT_EXPIRATION_TIME
7678
if token.get("refresh_token"):
7779
duration = token.get_claim("exp", "refresh_token") or DEFAULT_RT_EXPIRATION_TIME
7880

7981
self.__tokensCache.add(
8082
cachedKey,
81-
duration,
83+
duration - time.time(),
8284
token,
8385
)
8486

0 commit comments

Comments
 (0)