我决定从旧的azure portal创建应用程序并将应用程序设置为多租户 . 我为令牌和OAuth 2.0授权 endpoints (https://login.microsoftonline.com/common/oauth2/authorize)设置了OAuth 2.0令牌 endpoints (https://login.microsoftonline.com/common/oauth2/token)以进行授权 . 这是我的授权代码:header('location:https://login.microsoftonline.com/common/oauth2/authorize?response_type=code&scope=openid%20profile&client_id=xxxxxxxxxxxxxxx&redirect_uri=http://localhost/xxxxxxx/contacts/connectOffice');

这是我获取令牌的代码:

$data = array (
      'code' => $code,
      'client_secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=',
      'client_id' => 'xxxxxxxxxxxxxxxxxxxx',
      'grant_type' => 'authorization_code',
      'redirect_uri' => 'http://localhost/xxxxxx/contacts/connectOffice',
      'scope' =>'offline_access Contacts.ReadWrite'
    );
    $url = 'https://login.microsoftonline.com/common/oauth2/token';
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);      
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    $result = curl_exec($curl);

这是我从令牌请求中得到的结果:

阵列([token_type] =>承载[expires_in] => 3599 [ext_expires_in] => 0 [expires_on] => 1487828228 [的access_token] => AQABAAAAAADRNYRQ3dhRSrm-4K-adpCJ2ghMrdr3JJCVtGDvxtmOEHcFyxxxxxxxxxxxxxxxxvU_o8Ob_GixKxnHPPCAA [refresh_token] => AQABAAAAAADRxxxxxxxxxxx0EwuR_igY5qiAA [id_token] => eyJ0eXAiOiJKxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxFaxpRFq48A)

我正在使用此访问令牌,我用它来发送GET请求以访问Microsoft图形api(https://graph.microsoft.com/v1.0/me)以获取用户配置文件 . 这是我的获取请求:

$url = 'https://graph.microsoft.com/v1.0/me';
$headers = array(     
        "Authorization: Bearer ".$access_token                 
      );
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL, $url );               
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');              
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);               
$response=curl_exec($ch);

我收到此错误:

Array([error] => Array([code] => InvalidAuthenticationToken [message] => CompactToken解析失败,错误代码:-2147184105 [innerError] =>数组([request-id] => 43eae80b-c3f0-4909- a71d-4e5d3d982579 [date] => 2017-02-22T15:09:25)

任何人都可以建议我可能出错的地方?