InvalidAuthenticationToken - CompactToken 解析失败,错误代码:-2147184105
InvalidAuthenticationToken - CompactToken parsing failed with error code: -2147184105
我使用 V1 是为了获得来自 Microsoft REST 的令牌 API。 (我们有 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
它给了我一个结构为 follows on JWT 的令牌。它说签名无效但不确定是什么问题。
获得令牌后,我尝试了以下 curl 调用
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
header 的 Barer 是一个错字。正确的参数应该像 authorization: bearer {access_token}
.
其次,您似乎混合使用了 Azure V1.0 端点和 V2.0 端点。如果您使用 V1.0 端点开发哪些应用程序被 Azure 门户拒绝,当我们获取访问令牌时,我们需要指定 resource 参数而不是 scope。
scope 参数用于 Azure V2.0 端点,应用程序被 here.
抵制
Azure AD 的授权端点如下所示:
V1.0:
https://login.microsoftonline.com/{tenant}/oauth2/authorize
V2.0:
https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize?
有关 Azure AD 代码授权流程的更多详细信息,您可以参考以下链接:
Authorize access to web applications using OAuth 2.0 and Azure Active Directory
我使用 V1 是为了获得来自 Microsoft REST 的令牌 API。 (我们有 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
它给了我一个结构为 follows on JWT 的令牌。它说签名无效但不确定是什么问题。
获得令牌后,我尝试了以下 curl 调用
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
header 的 Barer 是一个错字。正确的参数应该像 authorization: bearer {access_token}
.
其次,您似乎混合使用了 Azure V1.0 端点和 V2.0 端点。如果您使用 V1.0 端点开发哪些应用程序被 Azure 门户拒绝,当我们获取访问令牌时,我们需要指定 resource 参数而不是 scope。
scope 参数用于 Azure V2.0 端点,应用程序被 here.
抵制Azure AD 的授权端点如下所示:
V1.0:
https://login.microsoftonline.com/{tenant}/oauth2/authorize
V2.0:
https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize?
有关 Azure AD 代码授权流程的更多详细信息,您可以参考以下链接:
Authorize access to web applications using OAuth 2.0 and Azure Active Directory