简体   繁体   English

Laravel - 如果我只有一个带有 email 和 ID 的 JWT 令牌,我如何为用户设置 Auth::attempt

[英]Laravel - How can i set the Auth::attempt to a user if i only have a JWT token with the email and the id

I have two projects;我有两个项目; the first is just a JWT login that redirects, if successful, to another Laravel project with the token.第一个只是一个 JWT 登录名,如果成功,它会重定向到另一个带有令牌的 Laravel 项目。 In the other project, Ivalidatede the token, but that project is already with a lot of code started, and it works with the methods Auth::user()->"retrieve data" .在另一个项目中,我验证了令牌,但该项目已经启动了很多代码,并且它使用方法Auth::user()->"retrieve data"

The problem is that I don't know how to authenticate with the Auth::attempt() , with only the email or the JWT, or what is the best way to do it, if I can delete all the lines with the Auth:: and instance the cookies, get the payload and replace the Auth::attempt() with some model for the cookie user.问题是我不知道如何使用Auth::attempt()进行身份验证,只有 email 或 JWT,或者最好的方法是什么,如果我可以删除所有带有 Auth 的行: : 并实例化 cookies,获取有效负载并将Auth::attempt()替换为 cookie 用户的一些 model。

Thanks, and sorry if my attempt to explain the issue is unclear.谢谢,对不起,如果我试图解释这个问题不清楚。 And if I'm doing something wrong, please let me know;如果我做错了什么,请告诉我; I'm a beginner at this.我是这方面的初学者。

I don't know if the best way to do this is to try the Auth::attempt / Auth::user or quit that and replace it with the payload that has the JWT in the cookie.我不知道最好的方法是尝试Auth::attempt / Auth::user还是退出它并用 cookie 中包含 JWT 的有效负载替换它。

Assuming you've correctly validated the user, you can login with Auth::login($user)假设您已经正确验证了用户,您可以使用Auth::login($user)

See the docs https://laravel.com/docs/9.x/authentication#authenticate-a-user-instance请参阅文档https://laravel.com/docs/9.x/authentication#authenticate-a-user-instance

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM