Passport: {"error":"invalid_client","message":"Client authentication failed"}

Created on 29 Dec 2017  ·  13Comments  ·  Source: laravel/passport

When passing form-data in postman, this works correctly:

json { "client_id": 3, "client_token": "gOX9axBrBuFVEVUPGSzjKIUqH77Ta64TuVIbHrky", "grant_type": "password", "password": "password1", "scope":"*", "username":"[email protected]" }

as soon as I switch to passing "application/json" and pass exactly the same values as a json object in the body, I get this error.

json {"error":"invalid_client","message":"Client authentication failed"}

Is the client id getting converted to a string somewhere in this process, and then failing to match? Definitely a bug with passport tho. changing the grant_type to "noodles" produces a different error:

json {"error":"unsupported_grant_type","message":"The authorization grant type is not supported by the authorization server.","hint":"Check the `grant_type` parameter"}

I'm putting my money on this being a type comparison issue in passport somewhere, where either the client_id or the client_token is incorrectly cast or compared.

Most helpful comment

@TimOgilvy There may be quite scenarios for the above issue.I will explain it one by one. You always need to pass application/json header .

  1. Make sure the client id and secret is in the oauth_clients and you passed those parameter correctly.In order to generate those client id and secret use _php artisan passport:install_.
  2. Make sure to use password grant client . To identify that goto oauth_clients table and check if password_client is set to 1 and personal_access_client is set to 0 and revoked to 0 .
    I hope this will solve the issue . Thank you

All 13 comments

the only other vague possibility seems to be the @ symbol in the email maybe not being decoded correctly

@TimOgilvy There may be quite scenarios for the above issue.I will explain it one by one. You always need to pass application/json header .

  1. Make sure the client id and secret is in the oauth_clients and you passed those parameter correctly.In order to generate those client id and secret use _php artisan passport:install_.
  2. Make sure to use password grant client . To identify that goto oauth_clients table and check if password_client is set to 1 and personal_access_client is set to 0 and revoked to 0 .
    I hope this will solve the issue . Thank you

{"error":"unsupported_grant_type","message":"The authorization grant type is not supported by the authorization server.","hint":"Check the grant_type parameter"}

yes, password_client is set to 1 and personal_access_client is set to 0 and revoked to 0

Closing this issue because it's already solved, old or not relevant anymore. Feel free to reply if you're still experiencing this issue.

how did you solve this issue

While try to login in laravel 5.7 passport

client_id:1
client_secret:vzdz0SEntm3xH6AMtKGBYbSc0vdxMaTXA
username:test.gmail.com
password:123456
grant_type:password
scope:*

{
"error": "invalid_credentials",
"message": "The user credentials were incorrect."
}

how to solve this issue

Thanks in advance..!!

@anususmi I think your username is wrong it should be [email protected] . And could you post your users database so that I may able to find the issue.

if you tried everything and still it's not working means try this solution!!
just give scope *.

$query = http_build_query([
    'client_id' => 1,
    'redirect_uri' => 'http://localhost:3000/callback',
    'response_type' => 'code',
    'scope' => '*'
]);

in my case this is the solution. I have checked

I try everything in this discussion. But still not work. Please help me. Because I'm stuck here almost a week.

I have tried different ways, in the end I notice that my config cache is old and I use this code and my problem solved

php artisan config:clear

Facing the same issue since morning in Laravel 8... "invalid_grant" I tried all suggestions mentioned in a loop but no success. Do anyone faced similar issue in laravel 8.

Any suggestions how to fix that
grant_type = password
client_id = 4
client_secret = SZ280jSp6YOrHNj6fglegAzi2rv8oqXtbt7T4gZA
scope = *
username = [email protected]
password = admin

DB row
-- | -- | -- | -- | -- | -- | -- | -- | -- | -- | --
4 | NULL | Laravel Password Grant Client | SZ280jSp6YOrHNj6fglegAzi2rv8oqXtbt7T4gZA | users | http://localhost | 0 | 1 | 0 | 2020-12-09 18:11:49 | 2020-12-09 18:11:49

Facing the same issue since morning in Laravel 8... "invalid_grant" I tried all suggestions mentioned in a loop but no success. Do anyone faced similar issue in laravel 8.

Any suggestions how to fix that
grant_type = password
client_id = 4
client_secret = SZ280jSp6YOrHNj6fglegAzi2rv8oqXtbt7T4gZA
scope = *
username = [email protected]
password = admin

DB row
-- | -- | -- | -- | -- | -- | -- | -- | -- | -- | --
4 | NULL | Laravel Password Grant Client | SZ280jSp6YOrHNj6fglegAzi2rv8oqXtbt7T4gZA | users | http://localhost | 0 | 1 | 0 | 2020-12-09 18:11:49 | 2020-12-09 18:11:49

First of all, please test this code
php artisan cache:clear
If your problem is not solved. I think the best way is to first check your token generation code in passport api, if your token was generated correctly. Next past client_id and client_secret in your login code to find out that where is the problem from

Was this page helpful?
0 / 5 - 0 ratings