【问题标题】:laravel passport oauth: Client error: `POST http://127.0.0.1:8000/oauth/token` resulted in a `400 Bad Request` response:laravel 护照 oauth:客户端错误:`POST http://127.0.0.1:8000/oauth/token` 导致 `400 Bad Request` 响应:
【发布时间】: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


    【解决方案1】:

    在 oauth/authorize 重定向后点击的帖子似乎缺少一些参数。这通常是因为代码必须已过期。我建议进行整个登录 - 再次授权周期。

    【讨论】:

    • 我必须说,我对这个评论持怀疑态度,但你是对的。您可能会花费太多时间试图了解问题所在,多次按 F5,而事实是,什么都不会改变。令牌已过期:)
    猜你喜欢
    • 1970-01-01
    • 2017-07-17
    • 1970-01-01
    • 1970-01-01
    • 2014-05-14
    • 1970-01-01
    • 2016-03-01
    • 1970-01-01
    • 2020-04-01
    相关资源
    最近更新 更多