Home > Software engineering >  Laravel HTTP Client - LinkedIn Authentication - A required parameter "grant_type" is missi
Laravel HTTP Client - LinkedIn Authentication - A required parameter "grant_type" is missi

Time:01-15

Greetings fellow developers,

So I am trying to retrive an access token from linkedin over Laravel with HTTP Client (Guzzle).

I'm using the following code:

$request = Http::asForm()->post("https://www.linkedin.com/oauth/v2/accessToken", [
            'form_params' => [
                'client_id' => config('services.linkedin.client_id'),
                'client_secret' => config('services.linkedin.client_secret'),
                'grant_type' => 'client_credentials'
            ]
        ])->json();

The problem is that instead of the getting the token, I am getting this:

array:2 [
  "error" => "invalid_request"
  "error_description" => "A required parameter "grant_type" is missing"
]

I've already tried all possible combinations I can remember, but I'm officially stuck.

Has anyone achieved this before? Or has any tips on what am I doing wrong?

CodePudding user response:

Looks correct according to LinkedIn api documentation. :/ You can try to dd the outgoing request to see if its being sent correctly. (If you are using Laravel 8.32 or higher)

$request = Http::dd()->asForm()->post(.......

Laravel HTTP dd

CodePudding user response:

Try

Http::asForm()->post("https://www.linkedin.com/oauth/v2/accessToken", [
    'client_id' => config('services.linkedin.client_id'),
    'client_secret' => config('services.linkedin.client_secret'),
    'grant_type' => 'client_credentials'
]);

You shouldn't need the form_params wrapper

  • Related