cody 007
cody 007

Reputation: 29

How to enable client credentials grant type in laravel passport

I am trying to develop a restful api using token for authentication using laravel 5.3 . I have also added laravel passport and I thought it will help me build the api faster. The resource I would like to give through api is common to all users , nothing specific to the user. So figured I should use grant type : client credentials. I couldn't find the any help about this grant type in laravel documentation

https://github.com/laravel/passport/pull/34/files this link shows the client credential grant type is added to laravel passport . but when I try to give grant type as client credential

    $http = new \GuzzleHttp\Client;
    $response = $http->post('http://site.dev/oauth/token', [
        'form_params' => [
            'grant_type' => 'client_credentials',
            'client_id' => config('api.client_id'),
            'client_secret' => config('api.client_secret'),
            'redirect_uri' => config('api.redirect_uri'),
     ],
    ]);

it gives error in grant type used.

Upvotes: 2

Views: 6901

Answers (2)

Jathin Prasad
Jathin Prasad

Reputation: 119

I was using client credentials method because it was a machine to machine call. I got error like { "error": "Unauthenticated." }` when using postman. I used Access type and Authorization headers but was getting the same error. Then I googled and tried the method explained in below link. It worked. :) :) http://filljoyner.com/2017/03/01/how-to-use-client-credentials-grant-tokens-for-your-api-authorization-with-laravel-5-4s-passport/

Upvotes: 2

fj.agmedia
fj.agmedia

Reputation: 87

When you install Laravel Passport one password grant in installed by default in oath_clients table, but password_client column should be 1 not 0.
Then you send some form_data to /oauth/token url and get access_token in return.

Upvotes: 1

Related Questions