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

孤街浪徒 提交于 2019-12-10 22:47:56

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/50364110/how-to-verify-laravel-passport-api-token-in-node-socket-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!