Laravel Passport:手动创建访问令牌

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47903457/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 17:08:05  来源:igfitidea点击:

Laravel Passport: Create access token manually

phplaravelapioauthlaravel-passport

提问by Catalin I.

I'm trying to find a way to create an access token manually in Laravel 5.5 using Passport and can't seem to figure it out.

我试图找到一种使用 Passport 在 Laravel 5.5 中手动创建访问令牌的方法,但似乎无法弄清楚。

I have 2 applications, one that holds the frontend and one api. The user receives an invitation via mail, and when he accesses the link, i wish to create the auth token and send it back in the response.

我有 2 个应用程序,一个包含前端,一个 api。用户通过邮件收到邀请,当他访问链接时,我希望创建身份验证令牌并将其发送回响应。

Any ideas on how to do this ? Thanks.

关于如何做到这一点的任何想法?谢谢。

回答by Catalin I.

Solved it myself. It seems that the HasApiTokenstrait that you put on the users model has a method to create a token

自己解决了。似乎您放在用户模型上的HasApiTokens特征具有创建令牌的方法

$user->createToken($name, $scopes);