【发布时间】:2019-10-16 00:06:35
【问题描述】:
我希望关联整个 Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectEvents(OnRedirectToIdentityProvider、OnAuthorizationCodeReceived 等)中的所有调用。
我希望将 OnRedirectToIdentityProvider 中的 'state' 参数设置为 GUID,以便稍后在日志中关联调用,例如
OnRedirectToIdentityProvider = async context =>
{
var myGuid = Guid.NewGuid().ToString();
context.ProtocolMessage.State = myGuid;
_log.LogInformation("OnRedirectToIdentityProvider: {0}", myGuid);
...
},
OnAuthorizationCodeReceived = async context =>
{
_log.LogInformation("OnAuthorizationCodeReceived: {0}", context.ProtocolMessage.State);
...
},
...
在文档中,据说身份服务器将在令牌响应中回显状态值。 http://docs.identityserver.io/en/latest/endpoints/authorize.html
我还读到客户端负责验证此属性。
问题是:
我找不到任何关于何时使用 'state' 属性的特定资源,验证是由中间件自动处理还是我应该处理验证我自己在回调函数中?
在“状态”参数中使用 GUID 时我应该考虑哪些安全风险?
我应该考虑的优点/缺点?
问候, 一个
【问题讨论】:
-
由中间件处理,状态是唯一且不可猜测的,GUID可以作为状态参数。
-
谢谢,从源代码中找到了 Options.StateDataFormat.Unprotect() 方法。调试并使用此方法后,我可以看到设置 ProtocolMessage.State 值实际上只更改了 AuthenticationProperties.Items["OpenIdConnect.Userstate"] 值。所有其他属性保持不变。
标签: authentication asp.net-core identityserver4 openid-connect identityserver3