api接口401问题
用的jwt。
auth.php
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
/*
|--------------------------------------------------------------------------
| Authentication Guards
|--------------------------------------------------------------------------
|
| Next, you may define every authentication guard for your application.
| Of course, a great default configuration has been defined for you
| here which uses session storage and the Eloquent user provider.
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| Supported: "session"
|
*/
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'jwt',
'provider' => 'accounts',
],
],
/*
|--------------------------------------------------------------------------
| User Providers
|--------------------------------------------------------------------------
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| If you have multiple user tables or models you may configure multiple
| sources which represent each model / table. These sources may then
| be assigned to any extra authentication guards you have defined.
|
| Supported: "database", "eloquent"
|
*/
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
'accounts' => [
'driver' => 'eloquent',
'model' => App\Models\Admin\Account::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
api.php路由文件
Route::group(['middleware' => ['auth:api', 'checkAuth']], function () {
// 用户管理
Route::resource('account', 'AccountController')->except(['create', 'edit']);
// 状态
Route::patch('account/{account}/status', 'AccountController@changeStatus')->name('account.status');
// 角色管理
Route::resource('role', 'RoleController')->except(['create', 'edit']);
// 权限管理
Route::resource('permission', 'PermissionController')->except(['create', 'edit']);
});
登录后总是出现如下是什么原因,刷新下就可以正常访问
![api登录问题]
检查一下第一次请求的时候有没有带token
根据图上请求看,
checkNewMessage
接口鉴权失败了。查看这个请求是在那个业务流程中发出的,然后再看
checkNewMessage
接口里面的逻辑,是缺少什么参数会导致鉴权失败。把headers的图一并截取了才行啊!