From 34b63b2fe86a97e68f09d91bff97d104da725157 Mon Sep 17 00:00:00 2001 From: "Josephine.Rutten" Date: Fri, 20 Dec 2024 12:10:03 +0100 Subject: [PATCH] changed the sub as cache key into token_string as sub might be the same for multiple users --- src/cnaas_nms/tools/cache.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cnaas_nms/tools/cache.py b/src/cnaas_nms/tools/cache.py index 84f55af4..109a14f4 100644 --- a/src/cnaas_nms/tools/cache.py +++ b/src/cnaas_nms/tools/cache.py @@ -18,7 +18,7 @@ def get_token_info_from_cache(token: Token) -> Optional[dict]: """Check if the userinfo is in the cache to avoid multiple calls to the OIDC server""" try: with redis_session() as redis: # type: ignore - cached_token_info = redis.hget(REDIS_OAUTH_TOKEN_INFO_KEY, token.decoded_token["sub"]) + cached_token_info = redis.hget(REDIS_OAUTH_TOKEN_INFO_KEY, token.token_string) if cached_token_info: return json.loads(cached_token_info) except RedisError as e: @@ -33,7 +33,7 @@ def put_token_info_in_cache(token: Token, token_info) -> bool: try: with redis_session() as redis: # type: ignore if "exp" in token.decoded_token: - redis.hsetnx(REDIS_OAUTH_TOKEN_INFO_KEY, token.decoded_token["sub"], token_info) + redis.hsetnx(REDIS_OAUTH_TOKEN_INFO_KEY, token.token_string, token_info) # expire hash at access_token expiry time or 1 hour from now (whichever is sooner) # Entire hash is expired, since redis does not support expiry on individual keys expire_at = min(int(token.decoded_token["exp"]), int(time.time()) + 3600)