无效身份验证令牌 - 压缩令牌解析失败,错误代码:-2147184105



我正在使用V1来获得来自REST API Microsoft令牌。(我们有 Office 365 租户,我曾经成功获取所有资源没有任何问题,但现在没有了。

clientId =8a67......de4b6
clientSecret =J58k8....5EU=
redirectUri =http://example.com...
resourceUrl =https://graph.microsoft.com
authority = https://login.microsoftonline.com/f02633....a603/oauth2/token

https://login.microsoftonline.com/f0263...0be3/oauth2/authorize?client_id=8a6..b6&redirect_uri=http://example.com&response_type=code&scope=mail.read

它给了我一个代币,结构如下 JWT。它说无效的签名,但不确定出了什么问题。

获得令牌后,我尝试了以下卷曲调用

curl -i https://graph.microsoft.com/v1.0/me/messages -H 'Content-Type: application/x-www-form-urlencoded' -H 'Authorization: Barer eyJ.[TOKEN]...UNa6nfw'

我收到以下错误,而不是消息:

HTTP/1.1 401 Unauthorized
Content-Type: application/json; charset=utf-8Cl23
Server: Microsoft-IIS/8.5
request-id: af2390b1-a9b...5ab9
client-request-id: af2390,....a615ab9
x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"West US","Slice":"SliceA","ScaleUnit":"000","Host":"AGSFE_IN_4","ADSiteName":"WST"}}
X-Powered-By: ASP.NET
Date: Thu, 19 Jan 2017 23:55:43 GMT
Content-Length: 268
{
  "error": {
    "code": "InvalidAuthenticationToken",
    "message": "CompactToken parsing failed with error code: -2147184105",
    "innerError": {
      "request-id": "af2390b1-...5ab9",
      "date": "2017-01-19T23:55:44"
    }
  }
} 

我在SO上查看了类似的问题,但找不到任何解决方案。

首先,authorization标题的Barer是一个错别字。正确的参数应该像 authorization: bearer {access_token} .

其次,你似乎使用 Azure V1.0 终结点和 V2.0 终结点进行混合。如果使用 V1.0 终结点开发哪些应用受到 Azure 门户的抵制,则在获取访问令牌时,我们需要指定资源参数而不是范围

scope 参数用于 Azure V2.0 终结点,应用从此处被抵制。

Azure AD 的授权终结点如下所示:

1.0版:

https://login.microsoftonline.com/{tenant}/oauth2/authorize

2.0版:

https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize?

有关 Azure AD 的代码授予流的更多详细信息,可以参考以下链接:

使用 OAuth 2.0 和 Azure Active Directory 授权访问 Web 应用程序

v2.0 协议 - OAuth 2.0 授权代码流

最新更新