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
|
_type = AuthenticationType.CHAT_ANONYMOUS_USER
|
||||||
return ChatUserToken(application_access_token.application_id, None, access_token, _type,
|
return ChatUserToken(application_access_token.application_id, None, access_token, _type,
|
||||||
ChatUserType.ANONYMOUS_USER,
|
ChatUserType.ANONYMOUS_USER,
|
||||||
chat_user_id, ChatAuthentication(None, False, False)).to_token()
|
chat_user_id, ChatAuthentication(None)).to_token()
|
||||||
else:
|
else:
|
||||||
raise NotFound404(404, _("Invalid access_token"))
|
raise NotFound404(404, _("Invalid access_token"))
|
||||||
|
|
||||||
|
|||||||
@ -14,13 +14,11 @@ from common.utils.rsa_util import encrypt, decrypt
|
|||||||
|
|
||||||
|
|
||||||
class ChatAuthentication:
|
class ChatAuthentication:
|
||||||
def __init__(self, auth_type: str | None, is_auth: bool, auth_passed: bool):
|
def __init__(self, auth_type: str | None):
|
||||||
self.is_auth = is_auth
|
|
||||||
self.auth_passed = auth_passed
|
|
||||||
self.auth_type = auth_type
|
self.auth_type = auth_type
|
||||||
|
|
||||||
def to_dict(self):
|
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):
|
def to_string(self):
|
||||||
return encrypt(json.dumps(self.to_dict()))
|
return encrypt(json.dumps(self.to_dict()))
|
||||||
@ -28,7 +26,7 @@ class ChatAuthentication:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def new_instance(authentication: str):
|
def new_instance(authentication: str):
|
||||||
auth = json.loads(decrypt(authentication))
|
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:
|
class ChatUserToken:
|
||||||
|
|||||||
@ -45,7 +45,8 @@ class ChatAnonymousUserToken(AuthBaseHandle):
|
|||||||
if application_setting_model is not None:
|
if application_setting_model is not None:
|
||||||
application_setting = QuerySet(application_setting_model).filter(application_id=application_id).first()
|
application_setting = QuerySet(application_setting_model).filter(application_id=application_id).first()
|
||||||
if application_setting.authentication:
|
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(
|
return None, ChatAuth(
|
||||||
current_role_list=[RoleConstants.CHAT_ANONYMOUS_USER],
|
current_role_list=[RoleConstants.CHAT_ANONYMOUS_USER],
|
||||||
permission_list=[
|
permission_list=[
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user