【发布时间】:2017-09-16 04:11:13
【问题描述】:
我已经从 Laracast 复制了 Taylor Otwell 的前端/后端护照示例,在本地主机窗口上:后端运行 127.0.0.1:8000 和前端运行 127.0.0.:8080 当我尝试客户端 api 调用 - 127.0.0.1:8080/callback 我得到这个:
ClientException in RequestException.php line 111:
Client error: `POST http://127.0.0.1:8000/oauth/token`
resulted in a `400 Bad Request` response:
{"error":"invalid_request","message":"The request is missing a required
parameter, includes an invalid parameter value, (truncated...)
还有这个细节:
at Client request('post','http://127.0.0.1:8000/oauth/token',
array('form_params' => array('grant_type' => 'authorization_code',
'client_id' => 3,
'client_secret' =>'23GCROVkVMtQqKsJKmx2xPojiDU4TOOe3ZMvKvQh',
'redirect_uri' =>'http://127.0.0.1:8080/callback', 'code' => null),
'synchronous' =>true)) in Client.php line 87
at Client->__call('post', array('http://127.0.0.1:8000/oauth/token',
array('form_params' =>array('grant_type' => 'authorization_code',
'client_id' => 3,
'client_secret' =>'23GCROVkVMtQqKsJKmx2xPojiDU4TOOe3ZMvKvQh',
'redirect_uri' => 'http://127.0.0.1:8080/callback', 'code' => null))))in web.php line 3
以下是相关代码:
Route::get('/callback', function () {
$query = http_build_query([
'client_id' => 3,
'redirect_uri' => 'http://127.0.0.1:8080/callback',
'response_type' => 'code',
'scope' => ''
]);
return redirect('http://127.0.0.1:8000/oauth/authorize?'.$query);
});
Route::get('/callback', function (Request $request) {
$http = new GuzzleHttp\Client;
$response = $http->post('http://127.0.0.1:8000/oauth/token',[
'form_params' => [
'grant_type' => 'authorization_code',
'client_id' => 3,
'client_secret' => '23GCROVkVMtQqKsJKmx2xPojiDU4TOOe3ZMvKvQh',
'redirect_uri' => 'http://127.0.0.1:8080/callback',
'code' => $request -> code,
],
]);
return json_decode((string) $response->getBody(),true);
感谢任何建议
(仅供参考,我在用户模型中设置了 HasApiTokens 以及所有其他要求。我想知道这是否与尝试在本地主机上运行 laravel 客户端和 laravel 后端有关)。
【问题讨论】:
标签: laravel oauth laravel-passport