【问题标题】:setting Identityserver 'state' parameter as a GUID to correlate calls?将 Identityserver 'state' 参数设置为 GUID 以关联调用?
【发布时间】: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


【解决方案1】:

这是使用 GUID 作为 ProtocolMessage.State 属性值的有效方法。

在 OnRedirectToIdentityProvider 事件中设置 ProtocolMessage.State 后

context.ProtocolMessage.State = myGuid;

从源代码中发现正在使用 StateDataFormat.Unprotect() 方法对数据进行反序列化。我用这个来调试

context.Options.StateDataFormat.Unprotect("CfDJ8...yr7Rpx3DyQMwPw")

'state' 查询中的值实际上是一个序列化的 AuthenticationProperties 类。

AuthenticationProperties 类由中间件生成,ProtocolMessage.State 值实际上存储为响应中的 AuthenticationProperties.Items["OpenIdConnect.Userstate"]。 正如评论中提到的,中间件处理状态的验证。

【讨论】:

    猜你喜欢
    • 2019-07-07
    • 2021-07-17
    • 1970-01-01
    • 1970-01-01
    • 2020-05-04
    • 1970-01-01
    • 2013-04-07
    • 2014-03-06
    • 1970-01-01
    相关资源
    最近更新 更多