Microsoft图形访问令牌错误AADSTS90014:请求正文必须包含以下参数:'grant_type'

时间:2018-04-19 07:13:21

标签: php azure-active-directory microsoft-graph

我正在尝试在成功获取代码后从Microsoft Graph API获取访问令牌。

根据此培训链接编写代码: https://developer.microsoft.com/en-us/graph/docs/concepts/auth_v2_user

当我调用以下POST调用时,我收到错误: “AADSTS90014:请求正文必须包含以下参数:'grant_type'”

这是POST调用(使用PHP):

$clientId = "XXXXXXXXX-ded0-4150-80c6-37e326ff6b26";
$clientSecret = "XXXXXXXXXXuakCZYA701@#!";
$responseUri = "https%3A%2F%2Fmyserver.mydomain.com%2Fsugarcrmmaintest%2Fresponse.php";
$postUrl = "/common/oauth2/v2.0/token";     
$hostname = "login.microsoftonline.com";
$fullurl = "https://login.microsoftonline.com/common/oauth2/v2.0/token";

$headers = array(
    "POST " . $postUrl . " HTTP/1.1",
    "Host: " . $hostname,
    "Content-type: application/x-www-form-urlencoded",
);

$post_params = array(
    "client_id" => $clientId,                    
    "scope" => "offline_access%20calendars.readwrite",
    "code" => "XXXXXXXXXXADX8GCi6Js6SK82TsD2Pb7rKYvnsfWlNknact_Tq6rBJWkoiY5k0W8CfvQRwO-TwwrgBlMxpOel5uE4gT0k6LCY4u_aZxbPhj5u5ATDT1AJbXKdL39IuidFWoEoZ2i3awf7LYupb_eO-gI4wEVI2JYl2VoJ23tKwnHQVUWlRBxexYIEkzwE0U6EYqk5RKnm4UGfe1oukoi0BI5vHUpEtJ_J7Me-r4_8oeRfz1BHDwPv_HOXEw0rsmjHG_VyzVEjdsiU7RVOQBzxY1Ks79CcqpHPTPimSZLPqg4-jByURQryr7ueRMpgeys8kJxDiZnh9tw0QULjs0ZbrPBAhE7CeeHtBK0cGbu0zFY5I428BwtylIEqN-bQZc7Y5RRFBFnSYSs8nYMCM61YkXpRXmhPhxFM583o6wwUTO6ZIGmj99GG1j3Ys7XmC3Tn6xpOM8wEMKmcVkcHL4aH0EfO-heG6_59dpBSuonBPXU6DPa7axV89rHF-6A9vXvEHO6pwZFXXJlp1COTo8r4LuT0Q-gbcAx7wlkepdfGf0gHQcRiYWe953_rwPyRDfXmZnZEgOPUAzHJxvbVuLuI24xVohxjk73wCWpPFgM9lDN0bt40DsMdbICb28LE2cdc9TIspIdVj-aO7cEwMZQsgULzEAPcqXTRJpVEeLgUbMTjLChjwldGAHQyoYcPrbCWHP2oOnOjrQMgAA",
    "redirect_uri" => $responseUri,
    "grant_type" => "authorization_code",   
    "client_secret" => $clientSecret,
);

$curl = curl_init($fullurl);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $post_params);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_VERBOSE, 1);


$response = curl_exec($curl);

我在这个论坛上看了类似的帖子,但它没有解决它......

任何人都可以帮忙吗? :)

0 个答案:

没有答案