perf: oidc 替换原有的is_ajax方法,优化accountbackupexecution 迁移文件 (#11274)

Co-authored-by: feng <1304903146@qq.com>
This commit is contained in:
fit2bot
2023-08-14 18:37:28 +08:00
committed by GitHub
parent efe57b3ebe
commit c11ba16e4e
2 changed files with 35 additions and 13 deletions

View File

@@ -1,15 +1,14 @@
import time
import requests
import requests.exceptions
from django.core.exceptions import MiddlewareNotUsed
from django.conf import settings
from django.contrib import auth
from django.core.exceptions import MiddlewareNotUsed
from common.utils import get_logger
from .utils import validate_and_return_id_token
from .decorator import ssl_verification
from .utils import validate_and_return_id_token
logger = get_logger(__file__)
@@ -25,11 +24,16 @@ class OIDCRefreshIDTokenMiddleware:
def __call__(self, request):
# Refreshes tokens only in the applicable cases.
if request.method == 'GET' and not request.is_ajax() and request.user.is_authenticated and settings.AUTH_OPENID:
if request.method == 'GET' and not self.is_ajax(request) and \
request.user.is_authenticated and settings.AUTH_OPENID:
self.refresh_token(request)
response = self.get_response(request)
return response
@staticmethod
def is_ajax(request):
return request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest'
@ssl_verification
def refresh_token(self, request):
""" Refreshes the token of the current user. """