2016-04-23 142 views
1

我想在Laravel 5.2实现智威汤逊,但我得到这个错误:Laravel 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\[email protected]'); 
}); 

我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进行测试。

回答

3

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

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

请记住,您的路由不应该具有此登录的身份验证中间件,因为这仅用于身份验证。

+0

谢谢!这非常有帮助! – Jamie

+0

也适用于我! –