当我请求 url 重定向时,我无法获取 access_token,它总是重定向到登录
// 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/authorize,我无法获取令牌,它总是重定向到登录,
我解决了这个问题,因为我没有登录,对此我很抱歉,但是当我登录时,请求 url oauth/authorize ,它总是需要 golf.xiongmaojf.com 的用户名和密码,任何用户名和密码没用,
如果我点击取消它回应
{
"error": "invalid_client",
"message": "Client authentication failed"
}
我通过 reigster new app_client use oauth/clients 解决了这个问题,并得到了这个页面
我得到了 access_token