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

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

{
	"client_id": 3,
	"client_token": "gOX9axBrBuFVEVUPGSzjKIUqH77Ta64TuVIbHrky",
	"grant_type": "password",
	"password": "password1",
	"scope":"*",
	"username":"tim.ogilvy@mywork.com"
}

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.

{"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:

{"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.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 5
  • Comments: 15 (1 by maintainers)

Most upvoted comments

@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

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

@ShekhSaifuddin007 I had kind of the same error, I solved it adding the parameters to the request create

    $proxy = Request::create(
        'oauth/token',
        'POST',
        [
            'username' => $request->email,
            'password' => $request->password,
            'grant_type' => 'password',
            'client_id' => $client->id,
            'client_secret' => $client->secret,
            'scope' => '*'
        ]
    );

    return app()->handle($proxy);