https://github.com/tymondesigns/jwt-auth/issues/860
1 下载开发者版本
修改composer.json,添加 "tymon/jwt-auth": "dev-develop"
2 在
config/app.php
中添加provider
Tymon\JWTAuth\Providers\LaravelServiceProvider::class
3 发布配置
php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider"
4 生成个密钥
php artisan jwt:secret
5
config/auth.php
做点修改
6 Model里要做点事情了,我的Model是
App/Models/Users
7 使用示例
先将JWTAuth注入
设置Token
校验Token
在header
中添加如下头:
Authorization:Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjgwMDEvYWNjZXNzX3Rva2VuIiwiaWF0IjoxNDk2NTgzMjE1LCJleHAiOjE0OTY1ODY4MTUsIm5iZiI6MTQ5NjU4MzIxNSwianRpIjoidmlvRWd1RTNkTmtBODgxMyIsInN1YiI6MTMsInBydiI6ImRiYWEzMGJkNTRjNzUyNmI2MGIyN2UzNzk0ODI3ZmU4In0.ZZX5LNVe4qGJcWNrYO-f9EMFqVCF37cO4S0r_pxDyyE
json格式,为了方便看
{
"Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjgwMDEvYWNjZXNzX3Rva2VuIiwiaWF0IjoxNDk2NTgzMjE1LCJleHAiOjE0OTY1ODY4MTUsIm5iZiI6MTQ5NjU4MzIxNSwianRpIjoidmlvRWd1RTNkTmtBODgxMyIsInN1YiI6MTMsInBydiI6ImRiYWEzMGJkNTRjNzUyNmI2MGIyN2UzNzk0ODI3ZmU4In0.ZZX5LNVe4qGJcWNrYO-f9EMFqVCF37cO4S0r_pxDyyE"
}
作者:yieldHL
链接:https://www.jianshu.com/p/d5b42ca679be
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。