Skip to content

Commit

Permalink
Merge pull request #7438 from aldbr/v8.0_FIX_TokenManagerClient-cache…
Browse files Browse the repository at this point in the history
…dTokens

[8.0] fix: correctly set the duration of tokens in cache
  • Loading branch information
fstagni authored Feb 6, 2024
2 parents 74fe559 + 3e244f2 commit 2d5ab55
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/DIRAC/FrameworkSystem/Client/TokenManagerClient.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
""" The TokenManagerClient is a class representing the client of the DIRAC
:py:mod:`TokenManager <DIRAC.FrameworkSystem.Service.TokenManagerHandler>` service.
"""
import time

from DIRAC import S_OK, S_ERROR
from DIRAC.Core.Utilities import ThreadSafe
from DIRAC.Core.Utilities.DictCache import DictCache
Expand Down Expand Up @@ -70,15 +72,15 @@ 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"):
duration = token.get_claim("exp", "refresh_token") or DEFAULT_RT_EXPIRATION_TIME

self.__tokensCache.add(
cachedKey,
duration,
duration - time.time(),
token,
)

Expand Down

0 comments on commit 2d5ab55

Please sign in to comment.