如何在节点/套接字应用程序中验证Laravel Passport api令牌? [英] How to verify laravel passport api token in node / socket application?

查看:91
本文介绍了如何在节点/套接字应用程序中验证Laravel Passport api令牌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是关于laravel应用程序中的OAuth护照令牌,该令牌也使用套接字/节点表示服务器.

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

我需要在套接字服务器上实现身份验证机制.类似于本文的内容: https://m.dotdev.co/authenticate-laravel-5-user-account-in-nodejs-socket-io-using-json-web-tokens-jwt-f74009d612f8 .

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.

我已经使用自己的令牌建立了该机制.但是我更喜欢使用为Laravel API生成的令牌.

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?

推荐答案

我自己的解决方案是在laravel中为我的节点应用程序创建一个端点.

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

终结点实际上负责从Passport提供我的OAuth令牌.在简单的示例中就是这样.

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');

仅在通过客户端应用程序连接到套接字服务器之后,我必须发送令牌和userId,然后再调用laravel端点以通过userId验证令牌.当我的用户和令牌正常时,我就授予了收听该频道的权限.

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.

这篇关于如何在节点/套接字应用程序中验证Laravel Passport api令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆