Laravel Passport API调用代码参数null

时间:2016-12-20 10:33:06

标签: php laravel

我正在尝试使用Laravel客户端调用Laravel API。

以下是代码:

Route::get('/callback', function (Request $request) {
    $http = new GuzzleHttp\Client;

    $response = $http->post('http://galaxy.dev/oauth/token', [
        'form_params' => [
            'grant_type' => 'authorization_code',
            'client_id' => '3',
            'client_secret' => 'rrhaEv0B6NAFLyMFqvZrY87gkquFF2UwhAHPtd8L',
            'redirect_uri' => 'http://galaxy-game.dev/callback',
            'code' => $request->code,
        ],
    ]);
    return json_decode((string) $response->getBody(), true);
});

我从API获得此回复:

  

客户端错误:POST http://galaxy.dev/oauth/token导致400   错误请求响应:{“error”:“invalid_request”,“message”:“   请求缺少必需参数,包含无效参数   值,(截断...)

我在API错误日志中注意到了这一点:

  

客户 - >请求('post','http://galaxy.dev/oauth/token',   array('form_params'=> array('grant_type'=>'authorization_code',   'client_id'=> '3','client_secret'=>   'rrhaEv0B6NAFLyMFqvZrY87gkquFF2UwhAHPtd8L','redirect_uri'=>   'http://galaxy-game.dev/callback','code'=> null),'synchronous'=>   true))在Client.php第87行

它说

  

$ request-> code = null

有没有人有任何想法为什么会这样?这似乎是它失败的原因。我完全遵循了Laravel文档。任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

您好我通过将代码值保留为空来修复此问题:

'code' => '',

由于$request->codenull,这可能会导致此问题。