Am using a custom handler for websocket in laravel
web.php
WebSocketsRouter::webSocket('/app/{appKey}', \App\SocketServer\SocketHandler::class);
This router dose not accept middleware, thats why am trying to send the token from the frontend and get the user by token
SocketHandler.php
<?php
namespace App\SocketServer;
class SocketHandler extends WebSocketHandler
{
public function onOpen(ConnectionInterface $connection)
{
parent::onOpen($connection);
$guzzleRequest = $connection->httpRequest;
parse_str($guzzleRequest->getUri()->getQuery(), $getParameters);
$token = $getParameters['token'] ?? null;
if (!$token) {
throw new Exception('Token required', 401);
}
// Here am trying to get the user by the token
$user = //
Auth::login($user)
}
}
How to authenticate a user inside the SockerHandler class?
thank you
source https://stackoverflow.com/questions/77211741/how-to-manually-authenticate-users-in-laravel-passport-using-tokens
No comments:
Post a Comment