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

SureshR's avatar

Calling /oauth/token throw ConnectionException error

I have installed passport for my laravel laravel 12 application. written a custom function to get token by calling /oauth/token API. but it's throw ConnectionException error


Code:

$response = Http::asForm()->post(url('/oauth/token'), [ 'grant_type' => 'password', 'client_id' => '0199e689-f307-735f-a749-16ee71f52f5e', 'client_secret' => 'mCS2MepnNdqzBQra489hx6RQ4izi7PsenLniOPPX', 'username' => '[email protected]', 'password' => 'admin@123',
]); return $response->json();


Error:

Illuminate\Http\Client\ConnectionException cURL error 28: Operation timed out after 30010 milliseconds with 0 bytes received (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://localhost:8000/oauth/token

0 likes
1 reply
alex458's avatar

This timeout happens because you’re making an HTTP call back into the same app and the server handling your request can’t service a second request from itself, so it waits until cURL times out. Instead of sending an external request, handle the token generation inside Laravel by creating an internal request using \Laravel\Passport\Http\Controllers\AccessTokenController::issueToken($request) or app()->handle(Request::create('/oauth/token', 'POST', [...])). This way, it processes internally instead of trying to connect over HTTP. If you’re running in Docker, make sure you use the correct network host instead of localhost, and if you’re using Artisan’s built-in server, consider using a proper local web server that can handle concurrent requests. Once you move the call in-process, the connection timeout should go away.

Please or to participate in this conversation.