Laravel5.5 Jwt 1.0 beta 配置

https://github.com/tymondesigns/jwt-auth/issues/860

1 下载开发者版本

 
image.png

修改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 做点修改

 
指定guard
 
Model的修改

6 Model里要做点事情了,我的Model是 App/Models/Users

 
最重要的东西

7 使用示例

  1. 先将JWTAuth注入
 
注入JWTAuth
  1. 设置Token
 
获取Token
 
获取Token效果
  1. 校验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
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
posted @ 2018-03-12 16:54  爱你爱自己  阅读(616)  评论(0编辑  收藏  举报