Home > Blockchain >  invalid_grant for password grant_type Laravel Passport
invalid_grant for password grant_type Laravel Passport

Time:09-23

I am trying to create an access_token for my api but I have problem that show this message :

"error": "invalid_client",
"error_description": "Client authentication failed",
"message": "Client authentication failed"

and this my request data

{
  "username":"[email protected]",
  "password":"test1234",
  "grant_type":"password",
  "client_id": "2",
  "client_secret":"jScq3DMMeZctypnYb7f1ClEHyzybwTK1Yisqo09E"
}

and this my oauth_clients table

oauth_clients_table

CodePudding user response:

You need to send the following in request body.

{
  "username":"[email protected]",
  "password":"test1234",
  "grant_type":"password",
  "client_id": "2",
  "client_secret":"jScq3DMMeZctypnYb7f1ClEHyzybwTK1Yisqo09E"
}

The client credentials are being validated from the request body in the following method.

// League\OAuth2\Server\Grant\AbstractGrant 
// line 253 
protected function getClientCredentials(ServerRequestInterface $request)
    {
        [$basicAuthUser, $basicAuthPassword] = $this->getBasicAuthCredentials($request);

        $clientId = $this->getRequestParameter('client_id', $request, $basicAuthUser); // It is fetching from request body

        if (\is_null($clientId)) {
            throw OAuthServerException::invalidRequest('client_id');
        }

        $clientSecret = $this->getRequestParameter('client_secret', $request, $basicAuthPassword);

        if ($clientSecret !== null && !\is_string($clientSecret)) {
            throw OAuthServerException::invalidRequest('client_secret');
        }

        return [$clientId, $clientSecret];
    }

CodePudding user response:

You try to add scope in your request data.

{
  "username":"[email protected]",
  "password":"test1234",
  "grant_type":"password",
  "client_id": "2",
  "client_secret":"jScq3DMMeZctypnYb7f1ClEHyzybwTK1Yisqo09E",
  "scope" => ""
}

If you have any problems, tell me.

  • Related