【发布时间】:2021-03-17 02:40:54
【问题描述】:
我不明白为什么我在尝试连接到私人频道时会遇到这个问题。 我有与这篇文章 100% 相同的代码 - Unable to authenticate laravel private channel using Laravel echo server, redis and socket.io 虽然使用 redis 前缀不起作用... 它适用于简单的频道... 这是我的错误-
客户端无法通过身份验证,通过 laravel-echo-server 获得 HTTP 状态 403
这是我的代码 js-
window.Echo = new Echo({
broadcaster: 'socket.io',
host: window.location.hostname + ':6001',
auth: {
headers:
{
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
}
});
window.Echo.private('user.'+userIdentifier).listen('SomeTestEvent', function (e) {
...
}
routes/channels.php -
Broadcast::channel('user.{id}', function ($user, $id) {
return true; // returning always true just for test
});
BroadcastServiceProvider.php -
public function boot()
{
Broadcast::routes();
require base_path('routes/channels.php');
}
事件/SomeTestEvent.php -
public function broadcastOn()
{
return new PrivateChannel('user.'.$this->data['user_id']);
}
laravel-echo-server.json -
{
"authHost": "http://localhost:8000",
"authEndpoint": "/broadcasting/auth",
"clients": [
{
"appId": "e0ebecd04673b905",
"key": "39c2a1314e4ef8e2879486a4a3b91c1e"
}
],
"database": "redis",
"databaseConfig": {
"redis": {
"host": "localhost",
"port": "6379"
},
"sqlite": {
"databasePath": "/database/laravel-echo-server.sqlite"
}
},
"devMode": true,
"host": "",
"port": "6001",
"protocol": "http",
"socketio": {},
"secureOptions": 67108864,
"sslCertPath": "",
"sslKeyPath": "",
"sslCertChainPath": "",
"sslPassphrase": "",
"subscribers": {
"http": true,
"redis": true
},
"apiOriginAllow": {
"allowCors": false,
"allowOrigin": "*",
"allowMethods": "GET, POST",
"allowHeaders": "Origin, Content-Type, X-Auth-Token, X-Requested-With, Accept, Authorization, X-CSRF-TOKEN, X-Socket-Id"
}
}
【问题讨论】:
标签: laravel redis laravel-echo