PHP CURL API令牌检索



我已经阅读了多个板上的所有内容,但没有成功。。。需要智囊团的信任。

我得到的是:

HTTP/1.1 400错误请求
预加载{"error":"unsupported_grant_type"}

我的目标:从FQDN/api/token端点检索OAuth令牌

我有:端点,用户名&密码(无秘密或密钥(

我可以从shell中卷曲并获得令牌-我只是无法获得php来完成>/

我的代码已经不是我的了,因为我很确定我是问题所在,但以下是我目前试图使用的代码:(有人能指出我在哪里做布偶吗!(

$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://FQDN/api/token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{"grant_type":"password","username": "user@domain.com.au","password": "userPasswd"}",
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
"Content-Length: 96",
"Accept: application/json"
),
CURLOPT_HEADER => true,
CURLOPT_POST => true,
CURLOPT_HTTPAUTH => basic
));
$response = curl_exec($curl);
print_r(curl_getinfo($curl));
print_r($response);
curl_close($curl);

根据注释,您需要发送键值对:

$data = array(
"grant_type" => "password",
"username" => "username",
"password" => "password"
)
curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($data));

最新更新