【问题标题】:OAuth token submitted with the request can not be parsed无法解析随请求提交的 OAuth 令牌
【发布时间】:2026-01-13 02:20:02
【问题描述】:

我正在尝试实现一个导入用户在 Office 365 中的事件的客户端,以便我可以轻松地将它们显示在公司的应用程序中。

我设法让用户使用他/她的 Office 365 帐户进行身份验证并批准我的应用程序并获得一个 AccessToken,但是当我尝试使用该令牌从 API 检索事件时,我得到一个 401 HTTP 错误代码,没有正文,在标题中我有这个:

Content-Length →0
Date →Thu, 17 Mar 2016 08:56:00 GMT
Server →Microsoft-IIS/8.0
WWW-Authenticate →Bearer client_id="00000002-0000-0ff1-ce00-000000000000", trusted_issuers="00000001-0000-0000-c000-000000000000@*", token_types="app_asserted_user_v1 service_asserted_app_v1", authorization_uri="https://login.windows.net/common/oauth2/authorize", error="invalid_token",Basic Realm="",Basic Realm=""
X-BEServer →DB4PR06MB522
X-BackEndHttpStatus →401
X-CalculatedBETarget →DB4PR06MB522.eurprd06.prod.outlook.com
X-DiagInfo →DB4PR06MB522
X-FEServer →AM3PR06CA022
X-Powered-By →ASP.NET
request-id →de1963bc-36df-4473-81f6-66ec37e8b415
x-ms-diagnostics →2000001;reason="OAuth token submitted with the request can not be parsed.";error_category="invalid_token"

我从https://login.microsoftonline.com/common/oauth2/token 获得的令牌,正文如下:

grant_type=authorization_code
redirect_uri=https://example.com/redirect-uri
client_id=XXXXXXXX-XXXX-XXXX-XXXXXXXXXXXX
client_secret=[my-client-secret]
code=[code-received-from-user-auth]

我从上述调用中收到的令牌,我通过 Authorization 标头发送到https://outlook.office.com/api/v2.0/me/events,如下所示:

Authorization: Bearer [access-token]

我从这个调用中得到的响应状态是 401 Unauthorized,我得到一个空的正文,并且标题是这样的:

Content-Length →0
Date →Thu, 17 Mar 2016 08:56:00 GMT
Server →Microsoft-IIS/8.0
WWW-Authenticate →Bearer client_id="00000002-0000-0ff1-ce00-000000000000", trusted_issuers="00000001-0000-0000-c000-000000000000@*", token_types="app_asserted_user_v1 service_asserted_app_v1", authorization_uri="https://login.windows.net/common/oauth2/authorize", error="invalid_token",Basic Realm="",Basic Realm=""
X-BEServer →DB4PR06MB522
X-BackEndHttpStatus →401
X-CalculatedBETarget →DB4PR06MB522.eurprd06.prod.outlook.com
X-DiagInfo →DB4PR06MB522
X-FEServer →AM3PR06CA022
X-Powered-By →ASP.NET
request-id →de1963bc-36df-4473-81f6-66ec37e8b415
x-ms-diagnostics →2000001;reason="OAuth token submitted with the request can not be parsed.";error_category="invalid_token"

你能告诉我我做错了什么吗?

【问题讨论】:

    标签: oauth-2.0 office365api


    【解决方案1】:

    我设法解决了我遇到的问题。

    为了将来参考,问题是我没有告诉 https://login.microsoftonline.com/common/oauth2/token 端点我需要令牌做什么。

    我必须提供一个资源参数,其中包含我要查询的资源的基本 url。 就我而言,它是https://outlook.office365.com

    【讨论】:

    • 嗨,我也面临同样的问题。你能详细告诉我该怎么做吗?谢谢
    • 我已经很久没有这样做了,但我认为您还需要在发送到login.microsoftonline.com/common/oauth2/token的正文中传递一个resource=[resource-endpoint]
    最近更新 更多