Pusher,存在和私人的不同身份验证?

Pusher, Different auth for presence and private?

我想知道如何为私人和在线频道实施授权,因为文档指出两者的授权不同。

https://pusher.com/docs/authenticating_users#implementing_private_endpoints

我目前在Laravel的认证过程是这样的

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());
    }
}

我正在按如下方式初始化频道

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\":\"miguel@clouddesign.be\",\"created_at\":\"2015-08-04 20:45:41\",\"updated_at\":\"2015-08-04 20:45:41\"}}, but got c880aa8f9d1337e4972fde05ae76148cd9a2a91e636d4714efbac2dff6d27f4b"}}}

有不同的函数来验证私有和状态通道,它们也采用不同的参数。

因此您应该检查 $request->get('channel_name') 并根据 private-presence- 的频道名称前缀使用适当的方法。这也让您有机会检查当前用户是否有权访问所请求的频道。