Laravel Passport API调用代码参数为null [英] Laravel Passport API call code parameter null

查看:57
本文介绍了Laravel Passport API调用代码参数为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to call a Laravel API using a Laravel Client.

以下是代码:

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 错误的请求响应:{错误":"invalid_request",消息": 请求缺少必需的参数,包括无效的参数 值,(被截断...)

Client error: POST http://galaxy.dev/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...)

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

Client-> request('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), '同步'=> true))在Client.php第87行

Client->request('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)) in Client.php line 87

$ request-> code = null

$request->code = null

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

Does anyone have any ideas why this might be? This seems to be the reason why it is failing. I have followed the Laravel docs exactly. Any help would be greatly appreciated!

推荐答案

我通过将代码值保留为空来解决了这个问题,

Hi I fixed this by leaving the code value empty like this:

'code' => '',

由于$request->codenull,可能会导致该问题.

Since $request->code is null, that probably causes that problem.

这篇关于Laravel Passport API调用代码参数为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆