我正在尝试使用Php代码中的Curl获取Azure Access令牌。摆脱困境。但是,邮递员工具中也有同样的细节。
"{"error":"invalid_request","error_description":"AADSTS90014: The request body must contain the following parameter: 'grant_type'.\r\nTrace ID: 9ea01200-70ff-4f4b-9b0d-a7b710f46200\r\
Adding the URL
$url = "https://login.microsoftonline.com/{tenent_id}/oauth2/token";
$grant_type = "client_credentials";
$client_id = "xxxxx";
$resource = "xxxx";
$client_secret = "xxxx";
//Declare Header
$headers = array();
$headers[] = 'Content-Type: x-www-form-urlencoded';
$post_params = array(
"grant_type" => "client_credentials",
"client_id" => $client_id,
"client_secret" => $client_secret,
"resource" => $resource,
);
//Curl Details
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_params);
$response = curl_exec($ch);
var_dump($response);