【问题标题】:Trying out OAuth2 via CURL - The grant type was not specified in the request通过 CURL 尝试 OAuth2 - 请求中未指定授权类型
【发布时间】:2016-08-27 22:07:14
【问题描述】:

我正在尝试在我的终端上使用 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"}

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

【问题讨论】:

    标签: php curl oauth oauth-2.0


    【解决方案1】:

    在您的 curl 请求中,当分隔参数时,您的 &&

    【讨论】:

    • 所以我应该使用 & 而不是 & ?
    • 是的,您使用 & 分隔参数。请参阅语法here
    猜你喜欢
    • 2014-10-27
    • 2020-05-11
    • 2018-05-27
    • 2022-11-14
    • 2021-04-24
    • 2021-07-05
    • 2019-12-12
    • 1970-01-01
    • 2017-02-23
    相关资源
    最近更新 更多