【发布时间】:2021-07-18 14:00:25
【问题描述】:
在客户端上将Pusher 与Echo 结合使用,我正在尝试使用Bearer 授权标头令牌通过api 对私有通道进行身份验证-但是我遇到了以下日志(THE最后的日志是错误的):
Pusher : : ["State changed","initialized -> connected"]
推动者 : : ["正在连接",{"传输":"ws","url":"ws://ws-mt1.pusher.com:80/app/************?protocol= 7&client=js&version=7.0.3&flash=false"}]
Pusher : : ["State changed","connecting -> connected with 新套接字 ID 224550.32180982"]
Pusher : : ["没有回调 在 private-App.User.17 for pusher:subscription_error"]
Pusher : : ["错误:从身份验证端点返回的 JSON 是 无效,但状态码为 200。数据为:\n\n\t\n\t\t\t
似乎我的服务器只是返回网页而不是 JSON 响应。
这是我的客户端设置:
Pusher.logToConsole = true
const PusherClient = new Pusher(PUSHER_APP_KEY,{
cluster: PUSHER_APP_CLUSTER,
wsHost: `ws-${PUSHER_APP_CLUSTER}.pusher.com`,
wssPort: 443,
enabledTransports: ['ws'],
forceTLS: true,
encrypted: true,
auth: {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
}
},
authEndpoint: http://127.0.0.1:8000/api/broadcasting/auth'
});
return new Echo({
broadcaster: 'pusher',
client: PusherClient
})
Laravel 服务器上api.php 中定义的广播路由:
Route::group(['middleware' => 'auth:api'], function () {
Broadcast::routes();
});
我在这里错过了什么?
【问题讨论】:
-
能不能把错误日志的截图完整加一下
-
尝试匹配您为验证用户而创建的身份验证令牌。
-
请介意看看这个问题:stackoverflow.com/questions/67605266/…
标签: laravel pusher laravel-echo pusher-js