【问题标题】:Laravel JWT Auth errorLaravel JWT 身份验证错误
【发布时间】:2016-08-17 07:28:59
【问题描述】:

我正在尝试在 Laravel 5.2 中实现 JWT,但出现此错误:

"message": "call_user_func_array() expects parameter 1 to be a valid callback, class 'Illuminate\\Auth\\TokenGuard' does not have a method 'once'",
  "status_code": 500,
  "debug": {
    "line": 288,
    "file": "/home/vagrant/Code/lsupport/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php",
    "class": "ErrorException",

我的路线文件:

$api = app('Dingo\Api\Routing\Router');

$api->version('v1',function($api)
{
    $api->post('login','App\Http\Controllers\Auth\AuthController@authenticate');
});

我的 AuthController:

 public function authenticate(Request $request)
    {
        $credentials = $request->only('email','password');

        try {
            if(!$token = JWTAuth::attempt($credentials)) {
                return $this->response->error(['error' => 'User credentials are not correct!'],401);
            }
        } catch(JWTException $ex) {
            return $this->response->error(['error' => 'Something went wrong!'],500);
        }
        return $this->response->item(compact('token'));
    }

我正在使用postman 进行测试。

【问题讨论】:

    标签: php laravel jwt dingo-api


    【解决方案1】:

    也有同样的问题,我通过在 config 文件夹内的 auth.php 文件中将我的默认保护设置为“web”来解决它。

    'defaults' => [
        'guard' => 'web',
        'passwords' => 'users',
    ],
    

    记住,你的路由不应该有这个登录的 auth 中间件,因为这只是为了验证。

    【讨论】:

    • 谢谢!!太有帮助了!
    猜你喜欢
    • 2020-03-18
    • 2020-01-05
    • 2018-09-13
    • 2017-11-29
    • 2019-01-07
    • 2017-05-13
    • 2020-07-23
    • 2020-06-26
    • 2016-07-28
    相关资源
    最近更新 更多