InvalidAuthenticationToken 和 CompactToken 问题 - 使用 PHP Curl 的 Microsoft Graph [英] InvalidAuthenticationToken and CompactToken issues - Microsoft Graph using PHP Curl

查看:19
本文介绍了InvalidAuthenticationToken 和 CompactToken 问题 - 使用 PHP Curl 的 Microsoft Graph的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够通过 oauth(参数:代码)等方式让用户登录成功地获取 access_token.但是,每次我尝试将授权标头(通过 php)发布到图形端点(例如/me),我最终得到了这个错误:

<上一页>{错误: {代码:无效身份验证令牌",消息:CompactToken 解析失败,错误代码:-2147184105",内部错误:{请求 ID:59cc0e42-90b7-445a-8bf7-009ff476bcbe",日期:2016-02-27T04:39:09"}}}

什么是 CompactToken 解析?有没有办法找出解决这个问题的方法?

注意:在撰写本文时,还没有适用于 Microsoft Graph 的 PHP SDK,所以我只是使用 php 进行 curl 调用

解决方案

这个错误显然是由于在 curl 请求中将 OAuth 令牌发送为 OAuth 而不是 Bearer.

这触发了上述错误:

<上一页>curl_setopt($ch,CURLOPT_HTTPHEADER,数组('内容类型:应用程序/json','内容长度:0','授权:OAuth'.$token));

这产生了成功的响应:

<上一页>curl_setopt($ch,CURLOPT_HTTPHEADER,数组('内容类型:应用程序/json','内容长度:0','授权:不记名'.$token));

I'm able to successfully fetch an access_token from having the user login via oauth (parameter: code) etc. However, each time I attempt to post the authorization header (via php) to a graph endpoint (such as /me), I end up getting this error:

{
error: {
code: "InvalidAuthenticationToken",
message: "CompactToken parsing failed with error code: -2147184105",
innerError: {
request-id: "59cc0e42-90b7-445a-8bf7-009ff476bcbe",
date: "2016-02-27T04:39:09"
}
}
}

What's CompactToken parsing? Is there a way to find out what's going on to fix this?

Note: at the time of this writing, there is no PHP SDK for Microsoft Graph, so I'm just making curl calls using php

解决方案

This error is apparently due to sending the OAuth token as OAuth instead of Bearer in the curl request.

This triggered the above error:

curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
    'Content-Type: application/json',                                                                                
    'Content-Length: 0',
    'Authorization: OAuth '.$token)                                                                       
);        

This yielded the successful response:

curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
    'Content-Type: application/json',                                                                                
    'Content-Length: 0',
    'Authorization: Bearer '.$token)                                                                       
);        

这篇关于InvalidAuthenticationToken 和 CompactToken 问题 - 使用 PHP Curl 的 Microsoft Graph的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆