Skip to content

Commit

Permalink
Fix presence channel authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
L3o-pold authored Feb 6, 2023
1 parent 7141005 commit 34eb852
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/AsyncClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -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.');
Expand Down Expand Up @@ -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];
}
}

0 comments on commit 34eb852

Please sign in to comment.