Reputation: 226
I have a private channel. And i can use it only if i authenticated on site. But in case of laravel passport i have no idea how it should be work. By default all what i need contains in cookies. What i have:
Broadcast::routes();
Broadcast::channel('App.User.{id}', function ($user, $id) {
return (int) $user->id === (int) $id;
});
Broadcast::routes(['middleware' => ['api']]);
have no effect.
How do I authenticate users through laravel passport, for that would be connected to a private channel websocket?
Upvotes: 2
Views: 1856
Reputation: 1589
I been through this, and my solution was using Laravel Echo & Laravel Echo Server for SocketIo.
Retrieve the user access token, then store it in cookie or application storage, and inject it while you instantiating or re-instantiating Laravel Echo, like the following:
let Echo = require('laravel-echo')
window.Echo = new Echo({
broadcaster: 'socket.io',
host: window.location.hostname + ':6001'
auth: {
headers: {
Authorization: 'Bearer ' + AUTH_API_TOKEN,
},
},
});
References:
Upvotes: 4
Reputation: 226
Unfortunately at the current moment the echo does not support authorization with the help of laravel passport, it is necessary to write your own sokket.io server.
Upvotes: 0