I'm trying to convert a curl request to Guzzle. In curl I'm getting the response where as in Guzzle it is giving error.
My curl request is
ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Basic " . base64_encode($client_id . ":" . $client_secret), 'Accept: application/json', 'Content-Type: application/x-www-form-urlencoded'));
$url = '<toke endpoint>';
curl_setopt($ch, CURLOPT_POSTFIELDS,
"grant_type=authorization_code&code=".$code."&redirect_uri=https://redirect-uri&scope=openid");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
print_r($result);
die;
For guzzle I've converted it as
$response = $client->post('<token end point>',[
'headers' => [
'Authorization' => "Basic " . base64_encode($client_id . ":" . $client_secret),
'Accept' => 'application/json',
'Content-Type' => 'application/x-www-form-urlencoded',
], [
'form_params' => [
'grant_type' => 'authorization_code',
'code' => $code,
'redirect_uri' => '<redirect-uri>',
'scope' => 'openid',
]]
]);
print_r($response);
echo '<pre>' . var_export($response->getStatusCode(), true) . '</pre>';
die;
The error I'm getting is {"error_description":"CWOAU0025E: The grant_type parameter was invalid: unknown","error":"unsupported_grant_type"}
I used to get this in curl also, then I've passed it as url in CURLOPT_POSTFIELDS. In guzzle it seems not to work.