Lawrence Phillips
Lawrence Phillips

Reputation: 1

Laravel Passport API call code parameter null

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

Here is the code:

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);
});

I get this response from the API:

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...)

I have noticed in the API error log this:

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

It says that

$request->code = null

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!

Upvotes: 0

Views: 1327

Answers (1)

utdev
utdev

Reputation: 4102

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

'code' => '',

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

Upvotes: 0

Related Questions