mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 01:33:05 +00:00
fix: 优化认证逻辑 (#724)
This commit is contained in:
parent
868e037522
commit
fd6aa4fb39
|
|
@ -7,14 +7,13 @@
|
|||
@desc: 认证类
|
||||
"""
|
||||
import traceback
|
||||
from importlib import import_module
|
||||
|
||||
from django.conf import settings
|
||||
from django.core import cache
|
||||
from django.core import signing
|
||||
from rest_framework.authentication import TokenAuthentication
|
||||
|
||||
from common.auth.handle.impl.application_key import ApplicationKey
|
||||
from common.auth.handle.impl.public_access_token import PublicAccessToken
|
||||
from common.auth.handle.impl.user_token import UserToken
|
||||
from common.exception.app_exception import AppAuthenticationFailed, AppEmbedIdentityFailed, AppChatNumOutOfBoundsFailed
|
||||
|
||||
token_cache = cache.caches['token_cache']
|
||||
|
|
@ -25,7 +24,16 @@ class AnonymousAuthentication(TokenAuthentication):
|
|||
return None, None
|
||||
|
||||
|
||||
handles = [UserToken(), PublicAccessToken(), ApplicationKey()]
|
||||
def new_instance_by_class_path(class_path: str):
|
||||
parts = class_path.rpartition('.')
|
||||
package_path = parts[0]
|
||||
class_name = parts[2]
|
||||
module = import_module(package_path)
|
||||
HandlerClass = getattr(module, class_name)
|
||||
return HandlerClass()
|
||||
|
||||
|
||||
handles = [new_instance_by_class_path(class_path) for class_path in settings.AUTH_HANDLES]
|
||||
|
||||
|
||||
class TokenDetails:
|
||||
|
|
|
|||
|
|
@ -8,3 +8,4 @@
|
|||
"""
|
||||
from .base import *
|
||||
from .logging import *
|
||||
from .auth import *
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
# coding=utf-8
|
||||
"""
|
||||
@project: MaxKB
|
||||
@Author:虎
|
||||
@file: auth.py
|
||||
@date:2024/7/9 18:47
|
||||
@desc:
|
||||
"""
|
||||
USER_TOKEN_AUTH = 'common.auth.handle.impl.user_token.UserToken'
|
||||
|
||||
PUBLIC_ACCESS_TOKEN_AUTH = 'common.auth.handle.impl.public_access_token.PublicAccessToken'
|
||||
|
||||
APPLICATION_KEY_AUTH = 'common.auth.handle.impl.application_key.ApplicationKey'
|
||||
|
||||
AUTH_HANDLES = [
|
||||
USER_TOKEN_AUTH,
|
||||
PUBLIC_ACCESS_TOKEN_AUTH,
|
||||
APPLICATION_KEY_AUTH
|
||||
]
|
||||
Loading…
Reference in New Issue