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登录问题]
api接口401问题

api接口401问题

《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
讨论数量: 3

检查一下第一次请求的时候有没有带token

2年前 评论
laravel_peng
  1. 根据图上请求看,checkNewMessage 接口鉴权失败了。

    file

  2. 查看这个请求是在那个业务流程中发出的,然后再看 checkNewMessage 接口里面的逻辑,是缺少什么参数会导致鉴权失败。

2年前 评论

把headers的图一并截取了才行啊!

2年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!