首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Laravel Passport API身份验证测试失败

Laravel Passport API身份验证测试失败
EN

Stack Overflow用户
提问于 2018-02-09 17:34:16
回答 1查看 673关注 0票数 1

我正在使用带有passport的laravel进行api身份验证。

当我测试包含用户登录代码的方法时,我得到一个stacktrace错误:

异常类限制不存在{“

”:“object

登录用户函数

代码语言:javascript
复制
  private function loginUser($user, $password)
{
    $client = DB::table('oauth_clients')->where('id', 2)->first();
    //form parameters to get access token
    $params = [
        'client_id' =>$client->id,
        'client_secret' =>  $client->secret,
        'grant_type' => 'password',
        'username' => $user->email,
        'password' => $password,
        'scope' => '*'
    ];

    $request = Request::create('oauth/token', 'POST',$params);
    $response = json_decode(Route::dispatch($request)->getContent());
    $data = array();
    if($response->access_token != null)
    {
        $data['response'] = config('app.success');
    }
    else
    {
        $data['response'] = config('app.failed');
    }
    $data['user'] = $user;
    $data['token'] = $response;

    return $data;
}

测试函数

代码语言:javascript
复制
public function testLoginUser()
{
    $user = User::find(1);

    $class = App::make('App\Http\Controllers\v1\Auth\api\PassportLogin');

    $methodName = 'loginUser';
    $method = $this->privateMethod($class,$methodName);;
    $data = $method->invokeArgs($class,array($user,'caramel'));
    $this->assertNotNull($data);

}

堆栈跟踪

{"exception":"object

testing.ERROR:类限制不存在

EN

回答 1

Stack Overflow用户

发布于 2018-06-01 07:50:47

将这一行添加到数组中可能会对您有所帮助。

代码语言:javascript
复制
protected $routeMiddleware = [
....
....
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
....

];

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48702739

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档