【发布时间】:2020-04-23 23:07:01
【问题描述】:
我正在开发一个具有 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
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",这让我相信事物的身份验证方面正在按预期工作。
谁能看到我错过了什么?
【问题讨论】:
标签: javascript reactjs laravel encryption pusher