mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 10:12:51 +00:00
fix: anonymous authentication (#3216)
This commit is contained in:
parent
6e0e0d2366
commit
c83bce3cef
|
|
@ -45,7 +45,7 @@ class AnonymousAuthenticationSerializer(serializers.Serializer):
|
|||
_type = AuthenticationType.CHAT_ANONYMOUS_USER
|
||||
return ChatUserToken(application_access_token.application_id, None, access_token, _type,
|
||||
ChatUserType.ANONYMOUS_USER,
|
||||
chat_user_id, ChatAuthentication(None, False, False)).to_token()
|
||||
chat_user_id, ChatAuthentication(None)).to_token()
|
||||
else:
|
||||
raise NotFound404(404, _("Invalid access_token"))
|
||||
|
||||
|
|
|
|||
|
|
@ -14,13 +14,11 @@ from common.utils.rsa_util import encrypt, decrypt
|
|||
|
||||
|
||||
class ChatAuthentication:
|
||||
def __init__(self, auth_type: str | None, is_auth: bool, auth_passed: bool):
|
||||
self.is_auth = is_auth
|
||||
self.auth_passed = auth_passed
|
||||
def __init__(self, auth_type: str | None):
|
||||
self.auth_type = auth_type
|
||||
|
||||
def to_dict(self):
|
||||
return {'is_auth': self.is_auth, 'auth_passed': self.auth_passed, 'auth_type': self.auth_type}
|
||||
return {'auth_type': self.auth_type}
|
||||
|
||||
def to_string(self):
|
||||
return encrypt(json.dumps(self.to_dict()))
|
||||
|
|
@ -28,7 +26,7 @@ class ChatAuthentication:
|
|||
@staticmethod
|
||||
def new_instance(authentication: str):
|
||||
auth = json.loads(decrypt(authentication))
|
||||
return ChatAuthentication(auth.get('auth_type'), auth.get('is_auth'), auth.get('auth_passed'))
|
||||
return ChatAuthentication(auth.get('auth_type'))
|
||||
|
||||
|
||||
class ChatUserToken:
|
||||
|
|
|
|||
|
|
@ -45,7 +45,8 @@ class ChatAnonymousUserToken(AuthBaseHandle):
|
|||
if application_setting_model is not None:
|
||||
application_setting = QuerySet(application_setting_model).filter(application_id=application_id).first()
|
||||
if application_setting.authentication:
|
||||
raise AppAuthenticationFailed(1002, _('Authentication information is incorrect'))
|
||||
if 'password' != chat_user_token.authentication.auth_type:
|
||||
raise AppAuthenticationFailed(1002, _('Authentication information is incorrect'))
|
||||
return None, ChatAuth(
|
||||
current_role_list=[RoleConstants.CHAT_ANONYMOUS_USER],
|
||||
permission_list=[
|
||||
|
|
|
|||
Loading…
Reference in New Issue