Javascript 如何在Parse.com中使用Pusher专用通道授权

Javascript 如何在Parse.com中使用Pusher专用通道授权,javascript,parse-platform,pusher,Javascript,Parse Platform,Pusher,我在互联网上找不到任何有用的信息,所以我想与大家分享。关于客户端: var pusher = new Pusher('your-app-key', {authTransport: 'parse'}); Pusher.authorizers.parse = function (socketId, callback) { var pusherData = { socket_id: socketId, channel_name: this.channel.

我在互联网上找不到任何有用的信息,所以我想与大家分享。

关于客户端:

var pusher = new Pusher('your-app-key', {authTransport: 'parse'});

Pusher.authorizers.parse = function (socketId, callback) {
    var pusherData = { 
        socket_id: socketId, 
        channel_name: this.channel.name 
    };
    Parse.Cloud.run('authorizePusherChannel', pusherData, {
        success: function (result) {
            callback(false, JSON.parse(result));
        },
        error: function (error) {
            callback(true, error);
        }
    });
};
在解析云上:

Parse.Cloud.define('authorizePusherChannel', function (request, response) {
    if (!request.user) { response.error('User should be autenticated.'); }
    var pusherAppKey = 'your-pusher-app-key';
    var pusherAppSecret = 'your-pusher-app-secret';
    var stringToSign = request.params.socket_id + ':' + request.params.channel_name;
    var authToken = pusherAppKey + ':' + crypto.createHmac('sha256', pusherAppSecret).update(stringToSign).    digest('hex');    
    response.success(JSON.stringify({auth:authToken}));
});

我认为这里缺少一个部分,它设置授权人使用
parse
one.@leggeter你说得对!在答案上加上。谢谢这对我不起作用。调用端点(由解析控制台调试确认)。响应看起来是一个有效的auth-keyed json…但是pusher控制台中出现了一个错误:“订阅私人聊天需要auth-info”
Pusher.authorizers.parse = function (socketId, callback) {
    var pusherData = { 
        socket_id: socketId, 
        channel_name: this.channel.name 
    };
    Parse.Cloud.run('authorizePusherChannel', pusherData, {
        success: function (result) {
            callback(false, JSON.parse(result));
        },
        error: function (error) {
            callback(true, error);