【发布时间】:2015-08-16 09:23:28
【问题描述】:
我正在使用 Identity Server v2 和 SessionAuthenticationModule。
我想添加一个新的 OWIN 应用程序(托管在 IIS 中),它可以与我现有的 STS 共享相同的会话 cookie“idsrvauth”。
请问我该怎么做?
- SessionAuthenticationModule 能否解密会话 cookie 并在 OWIN 应用程序中设置 IPrincipal?
- 或者我应该使用 OWIN 中间件来执行此操作吗?是否有现有的中间件,或者我需要编写新的中间件吗?
我在每个 web.config 中都有相同的 machineKey,但是在访问 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