无法从microsoft graph api获取用户个人资料信息

时间:2017-02-22 15:18:56

标签: azure oauth microsoft-graph php-curl

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

这是我获取令牌的代码:

$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);

我收到此错误:

  

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

有人可以提出我可能出错的地方吗?

0 个答案:

没有答案