Search code examples
node.jsapijwttokenlaravel-passport

How to verify laravel passport api token in node / socket application?


My question is about OAuth passport token in laravel application which is using sockets / node express sever as well.

I need to implement my authentication mechanizm on socket server. Something like this article: https://m.dotdev.co/authenticate-laravel-5-user-account-in-nodejs-socket-io-using-json-web-tokens-jwt-f74009d612f8.

Already Im building this mechanism with my own token. But I would prefer to use token generated for my Laravel API.

My point is how is this token builded ? Which fields of user are there and which keys are needed to check if token is valid on node server side? Is that even possible?


Solution

  • My own solution was to create an endpoint in laravel for my node application.

    The endpoint was actually responsible for veryfing my OAuth token from Passport. Something like that in simple example.

    Route::get('/user', function(Request $request) {
        return Auth::user()->id;
    })->middleware('auth:api');
    

    Just after connect to the socket server by client application, I must to send my token and userId and then after that make a call to the laravel endpoint to verify my token via userId. When my user and token was okey I give the permissions to listen the channel.