laravel passport 不通过 password 来生成 token,通过登录用户 id 来生成用户 token

重新搭建新的 laravel 项目,发现之前的 laravel passport 笔记,挺重要的一个知识点,博客没记,补上!

项目中使用 password 来生成 token,但是有其他需求,例如:
	1.使用 '手机号/验证码' 登录

	2.通过三方登录

	这些都不是 password 方法,这些我们可以自己来验证用户登录,然后通过登录用户的 id,给这些用户来分配 token

百度查了半天没找到,只能在 google 上搜索,不得不说,程序这东西,还是 google 给力,基本都能找到解决方法:

英语太差,但是只要大概单词没啥问题,都能搜索到类似的,我的关键词如下:
	laravel passport get token by user id, not password

参考文章:
	https://github.com/laravel/passport/issues/613
	https://github.com/laravel/passport/issues/71

解决方案:
	https://github.com/laravel/passport/issues/71#issuecomment-330506407(国人写的)

注意点:
	1.代码中
		use App\Entities\User;

		改为我们自己项目的 User 模型路径

	2.可能会出现权限错误:
		"Key file "file:///xxx/storage/oauth-private.key" permissions are not correct, should be 600 or 660 instead of 777"

		chmod -R 660 /xxx/storage/oatuh*

		同时得确保 /xxx/storage/oatuh* 对 www 用户有权限
		chown -R www:www /xxx/storage/oatuh*

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章