Skip to content

Commit c83bce3

Browse files
authored
fix: anonymous authentication (#3216)
1 parent 6e0e0d2 commit c83bce3

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

apps/chat/serializers/chat_authentication.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def auth(self, request, with_valid=True):
4545
_type = AuthenticationType.CHAT_ANONYMOUS_USER
4646
return ChatUserToken(application_access_token.application_id, None, access_token, _type,
4747
ChatUserType.ANONYMOUS_USER,
48-
chat_user_id, ChatAuthentication(None, False, False)).to_token()
48+
chat_user_id, ChatAuthentication(None)).to_token()
4949
else:
5050
raise NotFound404(404, _("Invalid access_token"))
5151

apps/common/auth/common.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,19 @@
1414

1515

1616
class ChatAuthentication:
17-
def __init__(self, auth_type: str | None, is_auth: bool, auth_passed: bool):
18-
self.is_auth = is_auth
19-
self.auth_passed = auth_passed
17+
def __init__(self, auth_type: str | None):
2018
self.auth_type = auth_type
2119

2220
def to_dict(self):
23-
return {'is_auth': self.is_auth, 'auth_passed': self.auth_passed, 'auth_type': self.auth_type}
21+
return {'auth_type': self.auth_type}
2422

2523
def to_string(self):
2624
return encrypt(json.dumps(self.to_dict()))
2725

2826
@staticmethod
2927
def new_instance(authentication: str):
3028
auth = json.loads(decrypt(authentication))
31-
return ChatAuthentication(auth.get('auth_type'), auth.get('is_auth'), auth.get('auth_passed'))
29+
return ChatAuthentication(auth.get('auth_type'))
3230

3331

3432
class ChatUserToken:

apps/common/auth/handle/impl/chat_anonymous_user_token.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ def handle(self, request, token: str, get_token_details):
4545
if application_setting_model is not None:
4646
application_setting = QuerySet(application_setting_model).filter(application_id=application_id).first()
4747
if application_setting.authentication:
48-
raise AppAuthenticationFailed(1002, _('Authentication information is incorrect'))
48+
if 'password' != chat_user_token.authentication.auth_type:
49+
raise AppAuthenticationFailed(1002, _('Authentication information is incorrect'))
4950
return None, ChatAuth(
5051
current_role_list=[RoleConstants.CHAT_ANONYMOUS_USER],
5152
permission_list=[

0 commit comments

Comments
 (0)