mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-05 09:21:02 +00:00
perf: oidc 替换原有的is_ajax方法,优化accountbackupexecution 迁移文件 (#11274)
Co-authored-by: feng <1304903146@qq.com>
This commit is contained in:
@@ -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. """
|
||||
|
Reference in New Issue
Block a user