perf: 修改支持 Django4

This commit is contained in:
ibuler
2023-07-24 11:52:25 +08:00
parent 16660575b7
commit b4b9c805ff
243 changed files with 546 additions and 614 deletions

View File

@@ -1,10 +1,10 @@
from django.conf import settings
from django.utils.module_loading import import_string
from django.utils.translation import ugettext_lazy as _
from common.utils import get_logger
from django.contrib.auth import get_user_model
from authentication.signals import user_auth_failed, user_auth_success
from django.utils.module_loading import import_string
from django.utils.translation import gettext_lazy as _
from authentication.signals import user_auth_failed, user_auth_success
from common.utils import get_logger
from .base import JMSModelBackend
logger = get_logger(__file__)

View File

@@ -1,22 +1,20 @@
# -*- coding: utf-8 -*-
#
import uuid
import time
import uuid
from django.core.cache import cache
from django.utils.translation import ugettext as _
from six import text_type
from django.contrib.auth import get_user_model
from django.core.cache import cache
from django.utils.translation import gettext as _
from rest_framework import HTTP_HEADER_ENCODING
from rest_framework import authentication, exceptions
from six import text_type
from common.auth import signature
from common.utils import get_object_or_none, make_signature, http_to_unixtime
from .base import JMSBaseAuthBackend
from ..models import AccessKey, PrivateToken
from .base import JMSBaseAuthBackend, JMSModelBackend
UserModel = get_user_model()
@@ -200,4 +198,3 @@ class SignatureAuthentication(signature.SignatureAuthentication):
return user, secret
except (AccessKey.DoesNotExist, exceptions.ValidationError):
return None, None

View File

@@ -1,7 +1,3 @@
from django.dispatch import Signal
oauth2_create_or_update_user = Signal(
providing_args=['request', 'user', 'created', 'name', 'username', 'email']
)
oauth2_create_or_update_user = Signal()

View File

@@ -9,8 +9,4 @@
from django.dispatch import Signal
openid_create_or_update_user = Signal(
providing_args=['request', 'user', 'created', 'name', 'username', 'email']
)
openid_create_or_update_user = Signal()

View File

@@ -11,8 +11,8 @@
import base64
import hashlib
import time
import secrets
import time
from django.conf import settings
from django.contrib import auth
@@ -20,13 +20,12 @@ from django.core.exceptions import SuspiciousOperation
from django.http import HttpResponseRedirect, QueryDict
from django.urls import reverse
from django.utils.crypto import get_random_string
from django.utils.http import is_safe_url, urlencode
from django.utils.http import url_has_allowed_host_and_scheme, urlencode
from django.views.generic import View
from authentication.utils import build_absolute_uri_for_oidc
from .utils import get_logger
logger = get_logger(__file__)
@@ -102,7 +101,7 @@ class OIDCAuthRequestView(View):
logger.debug(log_prompt.format('Stores next url in the session'))
next_url = request.GET.get('next')
request.session['oidc_auth_next_url'] = next_url \
if is_safe_url(url=next_url, allowed_hosts=(request.get_host(), )) else None
if url_has_allowed_host_and_scheme(url=next_url, allowed_hosts=(request.get_host(),)) else None
# Redirects the user to authorization endpoint.
logger.debug(log_prompt.format('Construct redirect url'))
@@ -145,15 +144,15 @@ class OIDCAuthCallbackView(View):
# missing or if no state can be retrieved from the current session.
if (
((nonce and settings.AUTH_OPENID_USE_NONCE) or not settings.AUTH_OPENID_USE_NONCE)
and
(
(state and settings.AUTH_OPENID_USE_STATE and 'state' in callback_params)
or
(not settings.AUTH_OPENID_USE_STATE)
)
and
('code' in callback_params)
((nonce and settings.AUTH_OPENID_USE_NONCE) or not settings.AUTH_OPENID_USE_NONCE)
and
(
(state and settings.AUTH_OPENID_USE_STATE and 'state' in callback_params)
or
(not settings.AUTH_OPENID_USE_STATE)
)
and
('code' in callback_params)
):
# Ensures that the passed state values is the same as the one that was previously
# generated when forging the authorization request. This is necessary to mitigate

View File

@@ -1,4 +1,3 @@
from django.dispatch import Signal
saml2_create_or_update_user = Signal(providing_args=('user', 'created', 'request', 'attrs'))
saml2_create_or_update_user = Signal()