Reputation: 9211
I'm wondering how to implement the Authorisation for both the Private and Presence channel, since the documentation states that the auth is different for the two.
https://pusher.com/docs/authenticating_users#implementing_private_endpoints
My current auth process in Laravel is this
public function auth(PusherManager $pusher, Request $request)
{
if(Auth::check())
{
echo $pusher->presence_auth('presence-channel', $request->get('socket_id'), Auth::user()->id, Auth::user());
}
}
And I'm initialising the channels as follows
var pusher = new Pusher('7c1df2e41d3c474d369d');
var presenceChannel = pusher.subscribe('presence-channel');
var notificationChannel = pusher.subscribe('private-notifications-' + me.id);
This is working for the Presence-channel, But when it comes to the Private-notifications channel I get the following error.
Pusher : Error : {"type":"WebSocketError","error":{"type":"PusherError","data":{"code":null,"message":"Invalid signature: Expected HMAC SHA256 hex digest of 52336.206126:private-notifications:{\"user_id\":1,\"user_info\":{\"id\":1,\"name\":\"Miguel Stevens\",\"email\":\"[email protected]\",\"created_at\":\"2015-08-04 20:45:41\",\"updated_at\":\"2015-08-04 20:45:41\"}}, but got c880aa8f9d1337e4972fde05ae76148cd9a2a91e636d4714efbac2dff6d27f4b"}}}
Upvotes: 1
Views: 1503
Reputation: 15467
There are different functions to authenticate private and presence channels that also take different parameters.
socket_auth($channel_name, $socket_id
should be used for Private channels: https://pusher.com/docs/authenticating_users#implementing_private_endpoints/lang=wordpresspresence_auth($channel_name, $socket_id, $user_id, $user_data)
should be used for Presence channels: https://pusher.com/docs/authenticating_users#implementing_presence_endpoints/lang=wordpressYou should therefore check the $request->get('channel_name')
and use the appropriate method based on the channel name prefix of private-
or presence-
. This also gives you the opportunity to check the current user has permission for the requested channel.
Upvotes: 1