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

Method authenticate

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

Source from the content-addressed store, hash-verified

102
103 # 重新 authenticate 方法,自定义认证规则
104 def authenticate(self, request):
105 auth = request.META.get('HTTP_AUTHORIZATION')
106 # 未认证
107 if auth is None:
108 raise AppAuthenticationFailed(1003, _('Not logged in, please log in first'))
109 if not auth.startswith("Bearer "):
110 raise AppAuthenticationFailed(1002, _('Authentication information is incorrect! illegal user'))
111 try:
112 token = auth[7:]
113 token_details = TokenDetails(token)
114 for handle in chat_handles:
115 if handle.support(request, token, token_details.get_token_details):
116 return handle.handle(request, token, token_details.get_token_details)
117 raise AppAuthenticationFailed(1002, _('Authentication information is incorrect! illegal user'))
118 except Exception as e:
119 maxkb_logger.error(f'Exception: {e}', exc_info=True)
120 if isinstance(e, AppEmbedIdentityFailed) or isinstance(e, AppChatNumOutOfBoundsFailed) or isinstance(e,
121 AppApiException):
122 raise e
123 raise AppAuthenticationFailed(1002, _('Authentication information is incorrect! illegal user'))
124
125
126class AllTokenAuth(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