通过CURL尝试OAuth2 - 请求中未指定授权类型

时间:2016-05-03 01:52:56

标签: php curl oauth oauth-2.0

我正在尝试在终端上使用CURL来执行OAuth客户端:

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

但我在服务器下面有以下错误:

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

但是如果我使用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;

我得到了正确答案:

{"access_token":"95d07fbb9964d567493c7517c25acde8a8b43ab6","expires_in":86400,"token_type":"Bearer","scope":"eggs-collect"}

任何想法为什么以及我错过了什么?

1 个答案:

答案 0 :(得分:1)

在您的卷曲请求中,在分隔参数时,您的&&