如何在IdentityServer 3中使用终端客户端状态参数?



我已经配置了IdentityServer 3使用指向AAD的外部IdentityProvider

到目前为止,当我向IdentityServer发送请求时,我被正确地重定向到AAD进行登录,然而,我发送给IdentityServer的"状态"参数被覆盖,OpenIdConnect.AuthenticationProperties的值被加密并作为查询字符串中的状态发送到AAD。

例如:

https://localhost:44333/idpaad/connect/authorize?client_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&redirect_uri=https://localhost:44394/&response_mode=query&response_type=code&scope=openid%20email&state=9b0e82c3-e623-42f1-bede-493243c103e7

,https://localhost:44333/idpaad/connect/authorizeIdentityServer端点state=9b0e82c3-e623-42f1-bede-493243c103e7→客户端生成的GUID作为querystring发送。

当我看到"RedirectToIdentityProvider";在IdentityServer OpenIdConnectAuthenticationNotifications的StartUp.cs中,将state的值更新为OpenIdConnect.AuthenticationProperties=(protected values)而不是GUID,同样也作为查询字符串返回给重定向URI。在这里输入图像描述是否有一种方法来发送原始状态,而不是由IdentityServer3覆盖它?

在使用wsFederation时,我没有得到这个问题,并且同样被直接转发到IdP。

感谢您的帮助。

大多数情况下,建议Azure Active Directory集成应用程序在向Azure AD发送登录请求时保持应用程序状态。推荐的实现方法是使用OpenID Connect标准中定义的"state"参数.

如果你从OpenID检查这个文档,你会发现使用state参数的主要原因是减轻CSRF攻击.

推荐。用于维护请求和回调之间状态的不透明值。通常,跨站点请求伪造(CSRF、XSRF)缓解是通过将此参数的值与浏览器cookie进行加密绑定来实现的。

' state '参数用于防止跨站请求伪造攻击,并在身份验证请求发生之前维护用户的状态.

ASP.NET or ASP.NET COREweb应用程序中使用OpenID连接OWIN中间件,在发出认证请求时,由中间件自动维护‘state’ parameter。,这是你看到state参数被覆盖的唯一原因。

但是如果你愿意,你可以在你的状态参数中添加自定义数据。在OpenIdConnectNotifications的RedirectToIdentityProvider中使用以下代码事件将自定义数据注入' state '参数。

var stateQueryString = notification.ProtocolMessage.State.Split('=');
var protectedState = stateQueryString[1];
var state = notification.Options.StateDataFormat.Unprotect(protectedState);
state.Dictionary.Add("MyData","123");
notification.ProtocolMessage.State = stateQueryString[0] + "=" + notification.Options.StateDataFormat.Protect(state);

有关详细信息,请参阅本文档和Microsoft身份平台和OpenID连接协议。

最新更新