1
votes

I have created an api with passport and want to use password grant tokens because it is more of application to application interactions. But i get below error when i try to access it.

GuzzleHttp\Exception\ClientException
Client error: `POST http://127.0.0.1:8000/oauth/token` resulted in a `401 Unauthorized` response: {"error":"invalid_client","error_description":"Client authentication failed","message":"Client authentication failed"}

my route

Route::get('/get_token_by_password', function (Request $request) {

    $http = new GuzzleHttp\Client;

    $response = $http->post('http://192.168.0.103:8000/oauth/token', [
    'form_params' => [
        'grant_type' => 'password',
        'client_id' => 13,
        'client_secret' => 'f37AwQGsVMiZDVu786KiRdbpn4MXYSBWCvqNcqiC',
        'username' => '[email protected]',
        'password' => '123456789',
        'scope' => '*',
    ],
]);

return json_decode((string) $response->getBody(), true);

})->name('get_token_by_password');
  1. What might I be doing wrong?

  2. Also, how do I use postman to get the token?

  3. How do i get a link to be used in other applications that want to consume my api
2

2 Answers

3
votes

The request seems correct. Check if you have correct keys and client. After, check in DB the new value of client_secret.

php artisan passport:keys

php artisan passport:client --password
0
votes

Your client id and/or client secret is not correct, since the error is "invalid_client".