(self, request)
| 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 | |
| 152 | class WebhookAuth(TokenAuthentication): |
nothing calls this directly
no test coverage detected