为api 调用提供身份校验功能
docs https://jwt-auth.readthedocs.io/
install
composer require tymon/jwt-auth
Add the service provider to the providers
array in the config/app.php
config file as follows:
'providers' => [
...
Tymon\JWTAuth\Providers\LaravelServiceProvider::class,
]
Run the following command to publish the package config file:
php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider"
Generate secret key
This will update your .env
file with something like JWT_SECRET=XXX
php artisan jwt:secret
该包 修改laravel api 路径下默认的 token校验方式 把token改为JWT token
其实生成流程和校验流程和之前没变化
login 通过用户账号密码 作为 credentials 然后去数据库获取用户信息 该用户信息会生成JWT token 放在laravel 默认缓存管理器
后续请求 在请求头带上 Authorazation : bear $token
通过auth:api 中间件校验