首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >微软中的oauth2连接

微软中的oauth2连接
EN

Stack Overflow用户
提问于 2018-02-28 03:21:04
回答 1查看 943关注 0票数 0

如何从Office 365日历和REST获取事件?

我在Azure中创建了一个应用程序,我有来自此请求的令牌:

代码语言:javascript
复制
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

接下来,我尝试获取事件:

代码语言:javascript
复制
$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中使用它来为页面用户从日历中编写事件。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-28 09:55:15

您指示的授权头错误。实际上,authorization头部使用的是Bearer <access_token>结构的持有者令牌。

代码语言:javascript
复制
$headersUser[] = 'Authorization: Bearer '.$jsonOutput['**access_token**'];
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49016406

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档