2016-12-01 58 views
1

当我请求URL重定向,我无法得到的access_token,它总是重定向到登录护照的OAuth /授权总是重定向登录固定的,但客户端身份验证失败

// First route that user visits on consumer app 
Route::get('/redirect', function() { 
    // Build the query parameter string to pass auth information to our request 
    $query = http_build_query([ 
     'client_id' => 1, 
     'redirect_uri' => 'http://app_golf.xiongmaojf.com/callback', 
     'response_type' => 'code', 
     'scope' => 'crud-bookmark-collections crud-bookmark-tags crud-bookmarks' 
    ]); 
// var_export($query); 
    // Redirect the user to the vOAuth authorization page 
    return redirect('http://golf.xiongmaojf.com/oauth/authorize?' . $query); 
}); 

// Route that user is forwarded back to after approving on server 
Route::get('/callback', function (Request $request) { 
    $http = new GuzzleHttp\Client; 

    $response = $http->post('http://golf.xiongmaojf.com/oauth/token', [ 
     'form_params' => [ 
      'grant_type' => 'authorization_code', 
      'client_id' => 1, // from admin panel above 
      'client_secret' => 'LNJhtWdGsDTQmei9x4lAh2BBfOmQkqXG3jdOjGRL', // from admin panel above 
      'redirect_uri' => 'http://app_golf.xiongmaojf.com/callback', 
      'code' => $request->code // Get code from the 
     ] 
    ]); 

    return json_decode((string) $response->getBody(), true)['access_token']; 
}); 

但请求URL的OAuth /授权,我可以我得到了这个问题,因为我没有登录,我很抱歉,但是当我登录时,请求url oauth/authorize,它总是需要golf.xiongmaojf.com的用户名和密码,任何用户名和密码都没有用,

enter image description here

,如果我clieck取消responsed

{ 
    "error": "invalid_client", 
    "message": "Client authentication failed" 
} 

我通过reigster新app_client使用OAuth /客户解决了这个问题,并得到了这个页面 enter image description here

我得到了ACCESS_TOKEN

+0

我已经解决了约重定向到/登录的问题,但我得到了另一个问题,它响应客户端身份验证失败 – zhangjun

回答

0

删除所有oauth表:

php artisan migrate:rollback --step=5 

和迁移所有:

php artisan migrate 

和:

php artisan passport:install --force 
0

确保你给了相同的URL http://app_golf.xiongmaojf.com/callback当供应商创建一个新的OAuth用户端。

当您的网址不一样时,可以显示此对话框。

如果不帮忙,还请尝试使用生成一个新的关键:

php artisan passport:keys