Closed Gemui closed 4 years ago
I see, I'll try to work on a fix to it, but, unfortunatelly I don't have write access on this repo, so, in any case we'll need to wait the mainteiners (@albertcht ) to merge it and it could take a little longer than you expect
Hi @Gemui ,
In laravel 5.x, basically developers can use built-in authentication in websocket out of the box. There might be some changes in newer versions of Laravel.
You can try to organize your own middleware in swoole_websocket.php
, and you can customize your auth middleware and replace it.
Software | Version |
---|---|
PHP | 8.0.8 |
Swoole | 4.7.0 |
Laravel | 8.51.0 |
laravel-swoole | 2.8 |
config/swoole_http.php
'providers' => [
Illuminate\Pagination\PaginationServiceProvider::class,
Illuminate\Auth\AuthServiceProvider::class,
\App\Providers\AuthServiceProvider::class,
],
config/swoole_websocket.php
'middleware' => [
SwooleTW\Http\Websocket\Middleware\DecryptCookies::class,
SwooleTW\Http\Websocket\Middleware\StartSession::class,
SwooleTW\Http\Websocket\Middleware\Authenticate::class,
],
Socket.io-Client v3
this.socket = io('http://localhost:80',
{
transports: ['websocket'],
withCredentials: true,
}
);
routes/websocket.php
Websocket::on('connect', function ($websocket, $request) {
var_dump("Trying to Access Authenticated User!");
$user = $request->user();
var_dump( $user );
var_dump( auth()->user() );
}
I have the same problem with authenticating trough guards and getting the user on:('connect').
The request and the guard always return NULL instead of the user.
I've tried to use the web the midleware from the documentation and also the web middleware. I am using Sanctum.
I am authenticating the user in a vuejs spa via post request to a route, getting a session cookie, then connecting with socket.io-client v3 to the websocket server of swoole. i am using the socket.io-client withHeader: true option, so its passing the cookies with the request to the websocket server. So then on:('connect'), i want to know the user, which is connecting by using the guard. But its always returning null.
How can i achieve, getting the correct user?
Environment Versions
Websocket Auth Problem Case
laravel-swoole have problem in authentication with laravel 7 i tested it in laravel 5.8 it working perfect but in version 7 user return null all time with any guard default or other as you can see
that trigger when i try to connect from socket io
swoole_http.php providers
i tried to change in package Authenticate but i got not thing
it's a bug in necessary feature i hope we found solution in fast time