How to manually authenticate users in laravel passport, using tokens - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Monday, October 2, 2023

How to manually authenticate users in laravel passport, using tokens

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