diff --git a/mozilla_django_oidc/middleware.py b/mozilla_django_oidc/middleware.py index 1b050325..67f3847e 100644 --- a/mozilla_django_oidc/middleware.py +++ b/mozilla_django_oidc/middleware.py @@ -120,8 +120,13 @@ def process_request(self, request): LOGGER.debug("request is not refreshable") return - expiration = request.session.get("oidc_id_token_expiration", 0) now = time.time() + + if hasattr(request, 'headers') and 'X-Refresh-OIDC-Token' in request.headers: + request.session['oidc_id_token_expiration'] = now + + expiration = request.session.get("oidc_id_token_expiration", 0) + if expiration > now: # The id_token is still valid, so we don't have to do anything. LOGGER.debug("id token is still valid (%s > %s)", expiration, now)