php - Auth guard 驱动程序 [api] 未定义

标签 php laravel laravel-5.3 jwt

我正在使用 laravel 5.4 并使用 jwt auth jwt 版本是 jwt-auth "tymon/jwt-auth": "0.5.*"

在 auth.php 中我有

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

        'api' => [
            'driver' => 'jwt',
            'provider' => 'users',
        ],
    ],

在 Api.php 中我有

 Route::post('/login','HomeController@authenticate');


Route::group(['prefix' => 'v2','middleware' => 'auth:api',], function () {

    // Authentication Routes...
   Route::get('/logout','HomeController@logout');
Route::get('/home','HomeController@home');

});

当我从 postman 那里邮寄电子邮件和密码时,它将返回 token 。

当我尝试访问时

http://localhost/demo/public/api/v2/home

和标题我通过了授权不记名 token

我在 postman 中收到以下错误

Whoops, looks like something went wrong. (1/1) InvalidArgumentException Auth guard driver [api] is not defined. in AuthManager.php (line 99) at AuthManager->resolve('api') in AuthManager.php (line 70) at AuthManager->guard('api') in Authenticate.php (line 61) at Authenticate->authenticate(array('api'))

能帮我解决一下吗

我还检查了自 2016 年 9 月 27 日以来的旧问题 https://github.com/tymondesigns/jwt-auth/issues/860

最佳答案

尝试设置 token :

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

        'api' => [
            'driver' => 'token', // here !
            'provider' => 'users',
        ],
    ],

关于php - Auth guard 驱动程序 [api] 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44465581/

相关文章:

laravel - 无法 Composer 转储自动加载 - 文件放置内容错误?

PHP MySQL 数组,如何获取 API 的特定结构?

php - php/sql 登录脚本故障排除

php - 如何将 PHP 父对象转换/转换为子对象?

php - Laravel 5.2 - 为 foreach() 提供的参数无效 - 使用 phpunit

laravel - Eloquent:如何结合预加载和数据透视过滤?

php - 我怎样才能建立统计 map ?

php - json 中缺少字段时无法更新数据库

php - Laravel 5.3 $appends 不工作

php - 如何获取在 Laravel 5.3 中执行的最后一个查询?