【问题标题】:How to share session cookie with Identity Server ASP.NET app and OWIN?如何与 Identity Server ASP.NET 应用程序和 OWIN 共享会话 cookie?
【发布时间】:2015-08-16 09:23:28
【问题描述】:

我正在使用 Identity Server v2 和 SessionAuthenticationModule。

我想添加一个新的 OWIN 应用程序(托管在 IIS 中),它可以与我现有的 STS 共享相同的会话 cookie“idsrvauth”。

请问我该怎么做?

  1. SessionAuthenticationModule 能否解密会话 cookie 并在 OWIN 应用程序中设置 IPrincipal?
  2. 或者我应该使用 OWIN 中间件来执行此操作吗?是否有现有的中间件,或者我需要编写新的中间件吗?

我在每个 web.config 中都有相同的 ma​​chineKey,但是在访问 OWIN 站点时,我得到了 CryptographicException:

CryptographicException: Error occurred during a cryptographic operation.
 System.Web.Security.Cryptography.HomogenizingCryptoServiceWrapper.HomogenizeErrors(Func`2 func, Byte[] input) +246
 System.IdentityModel.Services.MachineKeyTransform.Decode(Byte[] encoded) +200
 System.IdentityModel.Tokens.SessionSecurityTokenHandler.ApplyTransforms(Byte[] cookie, Boolean outbound) +173
 System.IdentityModel.Tokens.SessionSecurityTokenHandler.ReadToken(XmlReader reader, SecurityTokenResolver tokenResolver) +752
 System.IdentityModel.Tokens.SessionSecurityTokenHandler.ReadToken(Byte[] token, SecurityTokenResolver tokenResolver) +99
 System.IdentityModel.Services.SessionAuthenticationModule.ReadSessionTokenFromCookie(Byte[] sessionCookie) +1233
 System.IdentityModel.Services.SessionAuthenticationModule.TryReadSessionTokenFromCookie(SessionSecurityToken& sessionToken) +314
 System.IdentityModel.Services.SessionAuthenticationModule.OnAuthenticateRequest(Object sender, EventArgs eventArgs) +243
 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +80
 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +165

【问题讨论】:

  • 我决定在两个应用程序之间共享一个单独的 cookie,并让第一个应用程序负责创建会话数据。在第二个(OWIN)应用程序的 web.config 中,我删除了 SessionAuthenticationModule。

标签: cookies owin thinktecture-ident-server machinekey


【解决方案1】:

我遇到了类似的问题,在我的情况下,<machineKey ... > 元素中缺少 validation="SHA1"

根据MSDN,这是一个默认设置,但只有在明确添加后,我的基于机器密钥的加密开始在 2 个站点上工作。

【讨论】:

    猜你喜欢
    • 2010-09-23
    • 1970-01-01
    • 2011-02-28
    • 2011-02-02
    • 2018-12-24
    • 2023-03-27
    • 2017-09-03
    • 2015-01-25
    • 1970-01-01
    相关资源
    最近更新 更多