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*

 

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