From cb7c1ef3ee250a7839dd6a822cdd10e5f6a0d265 Mon Sep 17 00:00:00 2001 From: saadjavaid67 Date: Fri, 30 May 2025 14:22:25 +0500 Subject: [PATCH] Fix: auto update user_data to avoid Signature Invalidation in Laravel-Websocket --- src/pysher/pusher.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/pysher/pusher.py b/src/pysher/pusher.py index 20046e7..326a0c5 100644 --- a/src/pysher/pusher.py +++ b/src/pysher/pusher.py @@ -101,7 +101,7 @@ def subscribe(self, channel_name, auth=None): if auth is None: if channel_name.startswith('presence-'): data['auth'] = self._generate_presence_token(channel_name) - data['channel_data'] = json.dumps(self.user_data) + data['channel_data'] = self.user_data if isinstance(self.user_data, str) else json.dumps(self.user_data) elif channel_name.startswith('private-'): data['auth'] = self._generate_auth_token(channel_name) else: @@ -208,7 +208,12 @@ def _generate_presence_token(self, channel_name): headers=self.auth_endpoint_headers ) assert response.status_code == 200, f"Failed to get auth token from {self.auth_endpoint}" - auth_key = response.json()["auth"] + response_data = response.json() + auth_key = response_data["auth"] + try: + self.user_data = response_data["channel_data"] + except KeyError: + pass return auth_key def _build_url(self, secure=True, port=None, custom_host=None):