推送器不解密传入的通知

Pusher not decrypting incoming notifications

我正在开发一个具有 React 前端的 Laravel 应用程序。我使用推送器设置了通知,一切正常。

我正在尝试使用此处所述的端到端加密 https://pusher.com/docs/channels/using_channels/encrypted-channels

在我的 config/broadcasting.php 我有以下内容

'pusher' => [
    'driver' => 'pusher',
    'key' => env('PUSHER_APP_KEY'),
    'secret' => env('PUSHER_APP_SECRET'),
    'app_id' => env('PUSHER_APP_ID'),
        'options' => [
            'cluster' => env('PUSHER_APP_CLUSTER'),
            'useTLS' => true,
            'encryption_master_key' => env('PUSHER_ENCRYPTION_KEY'),
        ],
] 

在我的 .env 中设置了 PUSHER_ENCRYPTION_KEY,我可以在 Pusher 调试控制台中看到通知,按照我的预期进行了加密。

在我的前端,我像这样实例化 Pusher

const socket = new Pusher(process.env.MIX_PUSHER_APP_KEY, {
    cluster: process.env.MIX_PUSHER_APP_CLUSTER,
    authEndpoint: '/api/broadcasting/auth'
});
socket.subscribe('private-encrypted-user.' + props.user.id);

socket.bind('App\Events\TaskCreated' , function (data) {            
    console.log(data)
});

我可以在我的网络选项卡中看到 /api/broadcasting/auth 响应一个额外的字段,现在称为 shared_secret。根据文档,这用于解密传入的通知,解密应该是自动的。当我触发 App\Events\TaskCreated console.log(data) 运行但数据仍然是加密的。

它还在文档中说 if a client is unable to decrypt a message, it will make another request to your auth endpoint to obtain a new decryption key. If the client is still unable to decrypt the message with the new key, it will throw an error. 但没有抛出任何错误,也没有向 /api/broadcasting/auth

发出进一步的请求

我已启用 Pusher.logToConsole = true;,一切正常。我什至得到 "pusher_internal:subscription_succeeded","channel":"private-encrypted-user.2" 这让我相信事情的授权方面正在按预期工作。

谁能看到我错过了什么?

我解决了!

在我上面的代码中,当我需要将事件绑定到通道时,我将事件绑定到套接字。浪费了一天,但下面是工作代码,以防其他人遇到同样的问题

const socket = new Pusher(process.env.MIX_PUSHER_APP_KEY, {
    cluster: process.env.MIX_PUSHER_APP_CLUSTER,
    authEndpoint: '/api/broadcasting/auth'
});

const channel = socket.subscribe('private-encrypted-user.' + props.user.id);

channel.bind('App\Events\TaskCreated' , function (data) {            
    console.log(data)
});