Miguel Stevens
Miguel Stevens

Reputation: 9211

Pusher, Different auth for presence and private?

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

Answers (1)

leggetter
leggetter

Reputation: 15467

There are different functions to authenticate private and presence channels that also take different parameters.

You 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

Related Questions