Laravel Passport password grant returns Client authentication failed
Client authentication failedShort answer
invalid_client means Passport could not authenticate the client in your token request. Check that the password grant is enabled, that the client was created with passport:client --password, and that client_id and client_secret in the request match it. Public clients send no secret; confidential ones must.
Fix it fast
1Find out which cause you have
Send the token request with curl and read the JSON body. The error field tells invalid_client (the client) from invalid_grant (the user credentials).
curl -s -X POST https://your-app.test/oauth/token \ -d grant_type=password \ -d client_id=CLIENT_ID \ -d client_secret=CLIENT_SECRET \ -d username=user@example.com \ -d password=secret2Match what you see, then jump to its fix
- 1
invalid_client even though the id and secret were copied correctlyThe password grant is not enabled, or the client is not a password clientFix - 2
The request has no client_secret, or the value differs from the one shown when the client was createdclient_id or client_secret is wrong, or the secret is missingFix
- 1
What does the error look like?
Client authentication failedinvalid_client401 Unauthorized from /oauth/token
Cause 1 of 2
The password grant is not enabled, or the client is not a password client
1Check
The Passport docs say the password grant is switched on by calling enablePasswordGrant, and that a password grant client is created with the --password option of passport:client. Without both, token requests are refused.
grep -rn "enablePasswordGrant" app/2Fix
Enable the grant in AppServiceProvider::boot and create a client for it with the --password option, then use that client's id and secret.
// AppServiceProvider::boot()
Passport::enablePasswordGrant();
php artisan passport:client --password3Verify
Repeat the curl request from the first step with the new client.
php artisan route:list --path=oauth/tokenConfirmed by laravel.com
Cause 2 of 2
client_id or client_secret is wrong, or the secret is missing
1Check
RFC 6749 defines invalid_client as a failed client authentication, such as an unknown client or no client authentication included. Passport marks client_secret as required for confidential clients.
php artisan route:list --path=oauth/token2Fix
Send the exact id and secret of a password client. If you lost the secret, create a new client and use its values; for a public client that has no secret, leave client_secret out.
'client_id' => 'your-client-id',
'client_secret' => 'your-client-secret', // confidential clients only3Verify
The response now contains access_token and refresh_token.
curl -s -X POST https://your-app.test/oauth/token -d grant_type=password -d client_id=CLIENT_ID -d client_secret=CLIENT_SECRET -d username=user@example.com -d password=secretConfirmed by datatracker.ietf.org
How do I stop it coming back?
- Store the client id and secret in environment variables of the calling app, never in the mobile or browser bundle.
- Prefer a grant type the Passport docs currently recommend; the docs say password grant tokens are no longer recommended.
- Keep one note per environment of which client id belongs to which app.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Laravel Passport cannot find a personal access client
createToken fails for a user, and no token is returned
createToken needs a personal access client, and the database you are connected to does not have one.
3 causes, each with a fixBack end
Composer says the gd extension is missing on a Laravel project
composer install or composer update stops on a package that requires ext-gd
Composer refuses to install a package that requires ext-gd when the PHP binary running Composer has no GD extension.
4 causes, each with a fixBack end
composer require maatwebsite/excel fails to install
Composer says the package needs an older PHP than the one installed
Composer refuses maatwebsite/excel when the PHP version or a PHP extension does not match what the package and PhpSpreadsheet need.
3 causes, each with a fixBack end
composer install says the lock file is not compatible and asks for update
Your lock file does not contain a compatible set of packages. Please run composer update.
composer install checked the locked packages against this machine's PHP and extensions and found a conflict.
3 causes, each with a fixBack end
composer require laravel/horizon fails: ext-pcntl is missing
laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system
Horizon needs the pcntl extension, and Composer refuses to install it where PHP lacks that extension.
3 causes, each with a fixBack end
composer require laravel/passport stops with 'requirements could not be resolved'
... but these were not loaded, likely because it conflicts with another require.
Composer found no Passport release that fits your project at once.
4 causes, each with a fix