Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Added getAuthIdentifierForBroadcasting method #37408

Merged
merged 3 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Illuminate/Auth/Authenticatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ public function getAuthIdentifier()
return $this->{$this->getAuthIdentifierName()};
}

/**
* Get the unique broadcast identifier for the user .
*
* @return mixed
*/
public function getAuthIdentifierForBroadcasting()
{
return $this->getAuthIdentifier();
}

/**
* Get the password for the user.
*
Expand Down
5 changes: 4 additions & 1 deletion src/Illuminate/Broadcasting/Broadcasters/AblyBroadcaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,14 @@ public function validAuthenticationResponse($request, $result)

$channelName = $this->normalizeChannelName($request->channel_name);

$user = $this->retrieveUser($request, $channelName);
$broadcastIdentifier = method_exists($user, 'getAuthIdentifierForBroadcasting') ? $user->getAuthIdentifierForBroadcasting() : $user->getAuthIdentifier();

$signature = $this->generateAblySignature(
$request->channel_name,
$request->socket_id,
$userData = array_filter([
'user_id' => (string) $this->retrieveUser($request, $channelName)->getAuthIdentifier(),
'user_id' => (string) $broadcastIdentifier,
'user_info' => $result,
])
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,14 @@ public function validAuthenticationResponse($request, $result)

$channelName = $this->normalizeChannelName($request->channel_name);

$user = $this->retrieveUser($request, $channelName);
$broadcastIdentifier = method_exists($user, 'getAuthIdentifierForBroadcasting') ? $user->getAuthIdentifierForBroadcasting() : $user->getAuthIdentifier();

return $this->decodePusherResponse(
$request,
$this->pusher->presence_auth(
$request->channel_name, $request->socket_id,
$this->retrieveUser($request, $channelName)->getAuthIdentifier(), $result
$broadcastIdentifier, $result
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,11 @@ public function validAuthenticationResponse($request, $result)

$channelName = $this->normalizeChannelName($request->channel_name);

$user = $this->retrieveUser($request, $channelName);
$broadcastIdentifier = method_exists($user, 'getAuthIdentifierForBroadcasting') ? $user->getAuthIdentifierForBroadcasting() : $user->getAuthIdentifier();

return json_encode(['channel_data' => [
'user_id' => $this->retrieveUser($request, $channelName)->getAuthIdentifier(),
'user_id' => $broadcastIdentifier,
'user_info' => $result,
]]);
}
Expand Down
2 changes: 2 additions & 0 deletions tests/Broadcasting/AblyBroadcasterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ protected function getMockRequestWithUserForChannel($channel)
->andReturn(false);

$user = m::mock('User');
$user->shouldReceive('getAuthIdentifierForBroadcasting')
->andReturn(42);
$user->shouldReceive('getAuthIdentifier')
->andReturn(42);

Expand Down
2 changes: 2 additions & 0 deletions tests/Broadcasting/PusherBroadcasterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ protected function getMockRequestWithUserForChannel($channel)
->andReturn(false);

$user = m::mock('User');
$user->shouldReceive('getAuthIdentifierForBroadcasting')
->andReturn(42);
$user->shouldReceive('getAuthIdentifier')
->andReturn(42);

Expand Down
2 changes: 2 additions & 0 deletions tests/Broadcasting/RedisBroadcasterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ protected function getMockRequestWithUserForChannel($channel)
$request->channel_name = $channel;

$user = m::mock('User');
$user->shouldReceive('getAuthIdentifierForBroadcasting')
->andReturn(42);
$user->shouldReceive('getAuthIdentifier')
->andReturn(42);

Expand Down