Cookies 如何与Identity Server ASP.NET应用程序和OWIN共享会话cookie?

Cookies 如何与Identity Server ASP.NET应用程序和OWIN共享会话cookie?,cookies,owin,thinktecture-ident-server,machinekey,Cookies,Owin,Thinktecture Ident Server,Machinekey,我正在使用Identity Server v2和SessionAuthenticationModule 我想添加一个新的OWIN应用程序(托管在IIS中),它可以与我现有的STS共享同一个会话cookie“idsrvauth” 请问我该怎么做 SessionAuthenticationModule能否解密会话cookie并在OWIN应用程序中设置IPrincipal 或者我应该使用OWIN中间件来实现这一点?是否存在现有的中间件,或者是否需要编写新的中间件 我在每个web.config中都有相同

我正在使用Identity Server v2和SessionAuthenticationModule

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

请问我该怎么做

  • SessionAuthenticationModule能否解密会话cookie并在OWIN应用程序中设置IPrincipal
  • 或者我应该使用OWIN中间件来实现这一点?是否存在现有的中间件,或者是否需要编写新的中间件
  • 我在每个web.config中都有相同的machineKey,但在访问OWIN站点时,我会收到一个加密异常:

    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
    

    我有类似的问题,在我的例子中,它在
    元素中缺少
    validation=“SHA1”


    据我所知,这是一个默认的cookie,但只有在明确添加后,我的基于机器密钥的加密才开始在两个站点上工作。

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