File tree Expand file tree Collapse file tree 3 files changed +32
-4
lines changed Expand file tree Collapse file tree 3 files changed +32
-4
lines changed Original file line number Diff line number Diff line change 7
7
@desc: 认证类
8
8
"""
9
9
import traceback
10
+ from importlib import import_module
10
11
12
+ from django .conf import settings
11
13
from django .core import cache
12
14
from django .core import signing
13
15
from rest_framework .authentication import TokenAuthentication
14
16
15
- from common .auth .handle .impl .application_key import ApplicationKey
16
- from common .auth .handle .impl .public_access_token import PublicAccessToken
17
- from common .auth .handle .impl .user_token import UserToken
18
17
from common .exception .app_exception import AppAuthenticationFailed , AppEmbedIdentityFailed , AppChatNumOutOfBoundsFailed
19
18
20
19
token_cache = cache .caches ['token_cache' ]
@@ -25,7 +24,16 @@ def authenticate(self, request):
25
24
return None , None
26
25
27
26
28
- handles = [UserToken (), PublicAccessToken (), ApplicationKey ()]
27
+ def new_instance_by_class_path (class_path : str ):
28
+ parts = class_path .rpartition ('.' )
29
+ package_path = parts [0 ]
30
+ class_name = parts [2 ]
31
+ module = import_module (package_path )
32
+ HandlerClass = getattr (module , class_name )
33
+ return HandlerClass ()
34
+
35
+
36
+ handles = [new_instance_by_class_path (class_path ) for class_path in settings .AUTH_HANDLES ]
29
37
30
38
31
39
class TokenDetails :
Original file line number Diff line number Diff line change 8
8
"""
9
9
from .base import *
10
10
from .logging import *
11
+ from .auth import *
Original file line number Diff line number Diff line change
1
+ # coding=utf-8
2
+ """
3
+ @project: MaxKB
4
+ @Author:虎
5
+ @file: auth.py
6
+ @date:2024/7/9 18:47
7
+ @desc:
8
+ """
9
+ USER_TOKEN_AUTH = 'common.auth.handle.impl.user_token.UserToken'
10
+
11
+ PUBLIC_ACCESS_TOKEN_AUTH = 'common.auth.handle.impl.public_access_token.PublicAccessToken'
12
+
13
+ APPLICATION_KEY_AUTH = 'common.auth.handle.impl.application_key.ApplicationKey'
14
+
15
+ AUTH_HANDLES = [
16
+ USER_TOKEN_AUTH ,
17
+ PUBLIC_ACCESS_TOKEN_AUTH ,
18
+ APPLICATION_KEY_AUTH
19
+ ]
You can’t perform that action at this time.
0 commit comments