dingo/API 配合 JWT 鉴权问题

dingo/api 配合 JWT 鉴权问题

$api->group(['middleware' => 'api.auth'], function($api) {
        // 当前登录用户信息
        $api->get('owner', 'OwnersController@me')
            ->name('api.owner.show');
    });

此处 api.auth 默认是到users表中鉴权?


但是我 默认表不是users该怎么做?

 'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'api' => [
            'driver' => 'jwt',
            'provider' => 'users',
        ],
        'client'    =>  [
            'driver' => 'jwt',
            'provider' => 'owner',
        ]
    ],
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
最佳答案

@CrazyZard 解决了

$api->group(['middleware' => 'auth:client'], function($api) {
这样子就可以了

5年前 评论
讨论数量: 7

那就改了下面的users,看一下providers下的users 对应的是拿个模型,

5年前 评论
CrazyZard

file

file

就像这样

file

5年前 评论

@qingchunyibeifangzongle 不行的 这个是 JWT里面的中间件 鉴权 例如 写成 client.auth 就会报错 而api.auth自带的 默认到 users

5年前 评论

@CrazyZard

file

这样做 会提示鉴权失败。

$api->group(['middleware' => 'api.auth:client'], function($api) {

5年前 评论

@CrazyZard 解决了

$api->group(['middleware' => 'auth:client'], function($api) {
这样子就可以了

5年前 评论
CrazyZard

为什么是api.auth.:client 而不是 auth:client
@DonSen

5年前 评论

@CrazyZard 因为 看了一篇文章的一句话 api.auth是jwt内置中间件🤣 我尝试 像 auth('client') 这种方式写 不正确 认为 api.auth是 jwt内置中间件

5年前 评论

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