From 34eb8523b86a88b3cc1eb1fce4511e8fb5f8903d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9opold=20Jacquot?= Date: Mon, 6 Feb 2023 08:51:16 +0100 Subject: [PATCH] Fix presence channel authentication --- src/AsyncClient.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/AsyncClient.php b/src/AsyncClient.php index cf31ecf..1acf4ed 100644 --- a/src/AsyncClient.php +++ b/src/AsyncClient.php @@ -142,14 +142,14 @@ public function channel(string $channel): Observable $subscribe = $this->connected ->do(function (Event $event) use ($channel): void { - $authKey = null; + $authKey = $channelData = null; if (str_starts_with($channel, 'private-') || str_starts_with($channel, 'presence-')) { - $authKey = $this->generateAuthToken($channel, $event->getData()['socket_id']); + [$authKey, $channelData] = $this->generateAuthToken($channel, $event->getData()['socket_id']); } // Subscribe to pusher channel after connected - $this->send(Event::subscribeOn($channel, $authKey)); + $this->send(Event::subscribeOn($channel, $authKey, $channelData)); }) ->flatMapTo(Observable::empty()); @@ -265,7 +265,7 @@ private function handleLowLevelError(Throwable $throwable): Observable /** * @throws \Exception */ - private function generateAuthToken(string $channel, string $socketId): string + private function generateAuthToken(string $channel, string $socketId): array { if (!$this->authEndpoint) { throw new \Exception('No auth endpoint is configured to connect private or presence channel.'); @@ -299,6 +299,6 @@ private function generateAuthToken(string $channel, string $socketId): string throw new \Exception('Invalid response for auth token.'); } - return $response['auth']; + return [$response['auth'], $response['channel_data'] ?? null]; } }