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