MCPcopy
hub / github.com/1Panel-dev/MaxKB / authenticate

Method authenticate

apps/common/auth/authenticate.py:78–97  ·  view source on GitHub ↗
(self, request)

Source from the content-addressed store, hash-verified

76
77 # 重新 authenticate 方法,自定义认证规则
78 def authenticate(self, request):
79 auth = request.META.get('HTTP_AUTHORIZATION')
80 # 未认证
81 if auth is None:
82 raise AppAuthenticationFailed(1003, _('Not logged in, please log in first'))
83 if not auth.startswith("Bearer "):
84 raise AppAuthenticationFailed(1002, _('Authentication information is incorrect! illegal user'))
85 try:
86 token = auth[7:]
87 token_details = TokenDetails(token)
88 for handle in handles:
89 if handle.support(request, token, token_details.get_token_details):
90 return handle.handle(request, token, token_details.get_token_details)
91 raise AppAuthenticationFailed(1002, _('Authentication information is incorrect! illegal user'))
92 except Exception as e:
93 maxkb_logger.error(f'Exception: {e}', exc_info=True)
94 if isinstance(e, AppEmbedIdentityFailed) or isinstance(e, AppChatNumOutOfBoundsFailed) or isinstance(e,
95 AppApiException):
96 raise e
97 raise AppAuthenticationFailed(1002, _('Authentication information is incorrect! illegal user'))
98
99
100class ChatTokenAuth(TokenAuthentication):

Callers

nothing calls this directly

Calls 6

TokenDetailsClass · 0.85
getMethod · 0.45
supportMethod · 0.45
handleMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected