Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

yng's avatar
Level 1

laravel passport resulted in a `400 Bad Request`

I'm testing passport (Password Grant Token).

This command works properly.(on HomeStead, terminal)

curl -X POST -H 'Content-Type: application/json' -d '{"grant_type":"password", "client_id":"5", "client_secret":"4demeqgD0fyTonizGz45vngIbRj4TCK3PbSKvyz1", "username":"hey2@test.com", "password":"dydgns","scope":"*"}' http://192.168.10.10/oauth/token

but I typed this code, It not worked.

$headers = ['Content-Type' => 'application/json'];

$response = $http->post('http://192.168.10.10/oauth/token', [ 'headers' => $headers, 'form_params' => [ 'grant_type' => 'password', 'client_id' => '5', 'client_secret' => '4demeqgD0fyTonizGz45vngIbRj4TCK3PbSKvyz1', 'username' => $request->email, 'password' => $request->password, 'scope' => '', ], ]);

"message": "Client error: `POST http://192.168.10.10/oauth/token` resulted in a `400 Bad Request` response:\n{\"error\":\"unsupported_grant_type\",\"error_description\":\"The authorization grant type is not supported by the authorizatio (truncated...)\n",

thank!

0 likes
1 reply
yng's avatar
yng
OP
Best Answer
Level 1

I solved .

use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Client;

    $response = $http->post('http://localhost/oauth/token', [
        'form_params' => [
            'grant_type' => config('constants.p_grant_type'),
            'client_id' => config('constants.P_client_id'),
            'client_secret' => config('constants.P_client_secret'),
            'username' => $request->email,
            'password' => $request->password,
            'scope' => '',
        ],
    ]);

return json_decode((string) $response->getBody(), true);

important no need header (json) This is absolutely necessary.(json_decode)

Please or to participate in this conversation.