简体   繁体   English

oauth2在Microsoft中连接

[英]oauth2 connect in microsoft

How can I get events from Office 365 Calendar, from REST? 如何从REST的Office 365日历中获取事件?

I create an application in Azure, I have Token from this request: 我在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

Next i try get Events: 接下来,我尝试获取事件:

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

But I get an error: Access token validation failure . 但是我收到一个错误: Access token validation failure

What did I do wrong? 我做错了什么? I found examples for Laravel but I need simple, universal code. 我找到了Laravel的示例,但我需要简单的通用代码。 I need use this in Wordpress to write events from calendar for page users. 我需要在Wordpress中使用它来为页面用户编写日历中的事件。

You are indicating wrong authorization header. 您指示的授权标头错误。 In fact, the authorization header uses bearer token which has the structure: Bearer <access_token> . 实际上,授权标头使用具有以下结构的承载令牌: Bearer <access_token>

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM