AADSTS70007:请求令牌时,'query' 不是 'response_mode' 的受支持值

AADSTS70007: 'query' is not a supported value of 'response_mode' when requesting a token

所以我几天前在 Azure AD 中创建了一个应用程序。请求授权码时,当我同时请求 codeid_token(在 response_type 参数中)时,我收到以下错误消息:

AADSTS70007: 'query' is not a supported value of 'response_mode' when requesting a token

Trace ID: xxxx-xxxx-xxxx-xxxx-xxxx

Correlation ID: xxxx-xxxx-xxxx-xxxx-xxxx

Timestamp: 2018-06-13 16:06:03Z

我的请求 URL 看起来像这样:

https://login.microsoftonline.com/common/oauth2/authorize?resource=https%3A%2F%2Fmanagement.core.windows.net%2F&client_id=application-client-id&response_type=code+id_token&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_mode=query&nonce=1528906255418&state=12345

但是,如果我只请求 code 而不是 id_token,我不会收到任何错误。所以基本上,遵循 URL 有效:

https://login.microsoftonline.com/common/oauth2/authorize?resource=https%3A%2F%2Fmanagement.core.windows.net%2F&client_id=application-client-id&response_type=code&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_mode=query&nonce=1528906255418&state=12345

更有趣的是,如果我使用几个月前创建的应用程序的客户端 ID,该代码可以完美运行,并且 Azure AD returns 我 codeid_token.

我确实在这里发现了一个类似的问题:https://sharepoint.stackexchange.com/questions/242669/aadsts70007-query-is-not-a-supported-value-of-response-mode-when-requesting 但没有为该问题提供答案。

我很想知道:

两种不同的授权流程:

因此,这两种请求是不同的 OIDC 身份验证流程,因为它们的 response_types 不同。

同时,两个不同的 response_modes:

  • 对于 form_postform_post 执行包含重定向代码的 POST URI.When 授权响应仅使用一次,您应该在 reponse_mode 中使用 form_post。您还可以在 this documentation.

  • 中查看有关 form_post 的详细信息
  • 对于query,在这种模式下,授权响应参数被编码在重定向回客户端时添加到redirect_uri的查询字符串中。关于response_modequery的详细介绍,可以参考this documentation.

所以,对于不同的授权流程,你可能更清楚response_mode的不同。

对于Authorization code流,可以使用queryform_post,对于Hybird流,您可以使用form_postfragment。对于 Web 应用程序,我们建议使用 response_mode=form_post,以确保以最安全的方式将令牌传输到您的应用程序。 (Microsoft OpenId Connect 中间件只支持hybrid + form_post)

Why Azure AD does not throw any error for older application but for newer application? Has anything changed at the Azure AD level recently that will cause this problem? And that too for only newer applications.

我不是 100% 确定,但 AAD 不应更改其 authorization/authentication 级别的任何内容。也许您使用了不同类型的应用程序或身份验证流程。

Is there a way to prevent this error from happening? I would very much like to use query as response_mode instead of form_post.

由于OIDC框架的原因,我认为你不能使用query来混合流request.You最好使用form_post 在此流程中,如果您的应用是网络应用。

另外,Azure portal实际上是在使用这个流程,但可能和我们能用的有点不一样。但是您可以通过 Fiddler 捕获其 HTTP 流量来了解 authentication/authorization 是如何工作的。使用此流程,您必须启用您的应用程序以允许隐式流程。

您还可以看到this sample for Authenticate using Azure AD and OpenID Connect Hybrid flow in this documentaion

为了完整起见添加一个答案。韦恩的回答非常有帮助!

因此,我没有使用 response_type=query,而是使用了 response_type=fragment,我的新请求 URL 现在看起来如下所示:

https://login.microsoftonline.com/common/oauth2/authorize?resource=https%3A%2F%2Fmanagement.core.windows.net%2F&client_id=application-client-id&response_type=code+id_token&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_mode=fragment&nonce=1528906255418&state=12345

而且我能够同时取回 codeid_token: urn:ietf:wg:oauth:2.0:oob#code=code&id_token=id_token&state=12345&session_state=c6989d04-48ff-40cd-86ac-0cd2670ee168

删除了 urn:ietf:wg:oauth:2.0:oob#,然后解析了剩余的字符串以获取应用程序中的 codeid_token 值。