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

Method authenticate

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

Source from the content-addressed store, hash-verified

128
129 # 重新 authenticate 方法,自定义认证规则
130 def authenticate(self, request):
131 auth = request.META.get('HTTP_AUTHORIZATION')
132 # 未认证
133 if auth is None:
134 raise AppAuthenticationFailed(1003, _('Not logged in, please log in first'))
135 if not auth.startswith("Bearer "):
136 raise AppAuthenticationFailed(1002, _('Authentication information is incorrect! illegal user'))
137 try:
138 token = auth[7:]
139 token_details = TokenDetails(token)
140 for handle in all_handles:
141 if handle.support(request, token, token_details.get_token_details):
142 return handle.handle(request, token, token_details.get_token_details)
143 raise AppAuthenticationFailed(1002, _('Authentication information is incorrect! illegal user'))
144 except Exception as e:
145 maxkb_logger.error(f'Exception: {e}', exc_info=True)
146 if isinstance(e, AppEmbedIdentityFailed) or isinstance(e, AppChatNumOutOfBoundsFailed) or isinstance(e,
147 AppApiException):
148 raise e
149 raise AppAuthenticationFailed(1002, _('Authentication information is incorrect! illegal user'))
150
151
152class WebhookAuth(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