1. 安装 jwt-auth
composer require php-open-source-saver/jwt-auth
2. 设置 jwt secret
php artisan jwt:secret
会生成密钥在 .env中
$ php artisan jwt:secret
jwt-auth secret [AsfBEgjjw4XO752RxW8hYqgUc8TiI5uNkjk3oiK5NKRJQIerNGheHZvyzF8YUY8J] set successfully.
3. 修改 config/auth.php
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
// 增加这四行
'api' => [
'driver' => 'jwt',
'provider' => 'users',
],
],
4.修改或者自定义认证用户模型
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\System\UserModel::class,
],
5.自行封装登录逻辑