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