teelou teelou - 5 months ago 139x
PHP Question

Trying out OAuth2 via CURL - The grant type was not specified in the request

I am trying to use CURL on my terminal to perform a OAuth client:

curl -X POST -d "client_id=Barn Coop Farm&client_secret=b9c186fff02a3c40ffbe336017370ced&grant_type=client_credentials" http://coop.apps.knpuniversity.com/token

but I have this error below from the server:

{"error":"invalid_request","error_description":"The grant type was not specified in the request"}

But if I use PHP CURL:

$params = array();
$params['grant_type'] = 'client_credentials';
$params['client_id'] = 'Barn Coop Farm';
$params['client_secret'] = 'b9c186fff02a3c40ffbe336017370ced';

$url = 'http://coop.apps.knpuniversity.com/token';

$ch = curl_init();
$header = array ();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );

curl_setopt( $ch, CURLOPT_POSTFIELDS,$params);

$response = curl_exec( $ch );
echo $response;

I get the correct response:


Any ideas why and what have I missed?


In your curl request you have your & as & when separating the parameters.