Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Laravel Passport password grant returns Client authentication failed

ErrorClient authentication failed

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

  • Applies to Laravel 12, Laravel Passport, PHP 8.3
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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=secret
  2. 2Match what you see, then jump to its fix

    1. 1invalid_client even though the id and secret were copied correctlyThe password grant is not enabled, or the client is not a password clientFix
    2. 2The 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

What does the error look like?

  • Client authentication failed
  • invalid_client
  • 401 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 --password

3Verify

Repeat the curl request from the first step with the new client.

php artisan route:list --path=oauth/token

Confirmed by laravel.com

Did this fix it?

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/token

2Fix

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 only

3Verify

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=secret

Confirmed by datatracker.ietf.org

Did this fix it?

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

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 fix

Back 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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.