Skip to content
Snippets Groups Projects
Commit 1a700011 authored by Antoine Lambert's avatar Antoine Lambert
Browse files

auth/backends: Adjust TTL for cached OIDC userinfo

No need to substract 1 from computed TTLs as it can lead to cache userinfo
with a 0 seconds TTL when access token is about to expire and thus send
multiple userinfo requests to the OIDC server on successive calls to the
Web API.
parent 82282422
No related branches found
No related tags found
1 merge request!269auth/backends: Adjust TTL for cached OIDC userinfo
......@@ -152,8 +152,8 @@ class OIDCBearerTokenAuthentication(BaseAuthentication):
# create Django user
user = _oidc_user_from_info(userinfo)
# cache userinfo until token expires
max_ttl = decoded['exp'] - decoded['auth_time'] - 1
ttl = decoded['exp'] - int(timezone.now().timestamp()) - 1
max_ttl = decoded['exp'] - decoded['auth_time']
ttl = decoded['exp'] - int(timezone.now().timestamp())
ttl = max(0, min(ttl, max_ttl))
cache.set(decoded['sub'], userinfo, timeout=ttl)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment