InvalidAuthenticationToken 和 CompactToken 问题 - 使用 PHP Curl 的 Microsoft Graph问题、CompactToken、InvalidA

由网友(Slowly love(慢慢爱))分享简介:我能够通过 oauth(参数:代码)等方式让用户登录成功地获取 access_token.但是,每次我尝试将授权标头(通过 php)发布到图形端点(例如/me),我最终得到了这个错误:{错误: {代码:无效身份验证令牌",消息:CompactToken 解析失败,错误代码:-2147184105",内部错误:{请求 I...

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

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

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

惊 看看肥胖 代谢健康受损和 COVID 19的关系吧

注意:在撰写本文时,还没有适用于 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)                                                                       
);        

阅读全文

相关推荐

最新文章