簡體   English   中英

oauth2在Microsoft中連接

[英]oauth2 connect in microsoft

如何從REST的Office 365日歷中獲取事件?

我在Azure中創建一個應用程序,此請求中包含令牌:

https://login.microsoftonline.com/common/oauth2/v2.0/authorize?
  client_id=[app_id from AZURE]
  &response_type=code
  &redirect_uri=https://mypage_domain.com
  &response_mode=query
  &scope=https%3A%2F%2Fgraph.microsoft.com%2Fcalendars.read%20
  &state=12345

接下來,我嘗試獲取事件:

$ch = curl_init();
$headers = array();
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
$postFields = 'grant_type=authorization_code&code='.$authCode.'&redirect_uri='.$redirectUri.'&scope=openid&client_id='.$clientId.'&client_secret='.$clientSecret;

curl_setopt($ch, CURLOPT_URL,'https://login.microsoftonline.com/common/oauth2/v2.0/token');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$serverOutput = curl_exec ($ch);
curl_close ($ch);
$jsonOutput = json_decode($serverOutput, true);

$chUser = curl_init();
$headersUser[] = 'Authorization: Bearer '.$jsonOutput['id_token'];
curl_setopt($chUser, CURLOPT_URL,'https://graph.microsoft.com/v1.0/me/events/');
curl_setopt($chUser, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($chUser, CURLOPT_HTTPHEADER, $headersUser);
$serverOutputUser = curl_exec($chUser);
curl_close($chUser);

但是我收到一個錯誤: Access token validation failure

我做錯了什么? 我找到了Laravel的示例,但我需要簡單的通用代碼。 我需要在Wordpress中使用它來為頁面用戶編寫日歷中的事件。

您指示的授權標頭錯誤。 實際上,授權標頭使用具有以下結構的承載令牌: Bearer <access_token>

$headersUser[] = 'Authorization: Bearer '.$jsonOutput['**access_token**'];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM