I am using Laravel 11 and need to setup passport for authentication
Installation:
php artisan install:api --passport
Password grand setup
php artisan passport:client --password
The prompt suggested a name for the password grant and I pressed.
Ultimately it asked the following:
Which user provider should this client use to retrieve users?
I pressed enter, the client id & secret were generated, and I pasted them in my .env
.env
PASSPORT_PASSWORD_CLIENT_ID=9c7f6a4e-bb40-4766-8064-77a34b65911a
PASSPORT_PASSWORD_SECRET=vTNxpEBwcRbeFFZhCaVtunYYIWQLCrRtVmETPn5f
I added the following to config/auth.php
'api' => [
'driver' => 'passport',
'provider' => 'users',
],
Lastly, I added the following to the boot method of AppServiceProvider
Passport::enablePasswordGrant();
In api.php, I am attempting to request a token using a login route:
Route::post('/login', function(Request $request) {
$request_url = env('APP_URL') . '/oauth/token';
$response = Http::asForm()->post($request_url, [
'grant_type' => 'password',
'client_id' => env('PASSPORT_PASSWORD_CLIENT_ID'),
'client_secret' => env('PASSPORT_PASSWORD_SECRET'),
'username' => $request->email,
'password' => $request->password,
'scope' => '',
]);
return response()->json([
'data' => $response->json()
]);
}
In postman, I created a post request for
http://127.0.0.1:8000/api/login
and set the body tab to form data
I see the following error when I hit the send button:
cURL error 28: Operation timed out after 30006 milliseconds with 0 bytes received (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://127.0.0.1:8000/oauth/token
Is there anything I am missing in my setup?