[英]Share Cookie between application and sub application in ASP.NET Core
I am looking for a way to share a login screen between a root application and a sub application (Virtual Directory configured as an Application) in ASP.NET Core. 我正在寻找一种在ASP.NET Core中的根应用程序和子应用程序(配置为应用程序的虚拟目录)之间共享登录屏幕的方法。 The LoginPath for the sub application will be pointing to the root login page (which the returnUrl will then point back to the sub application).
子应用程序的LoginPath将指向根登录页面(然后returnUrl将其指向子应用程序)。 Basically, I need the sub application to recognize the credentials set by the root application.
基本上,我需要子应用程序来识别由根应用程序设置的凭据。 I am using cookie authentication.
我正在使用cookie身份验证。
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationScheme = "Cookie",
LoginPath = new PathString("./signin/"),
AccessDeniedPath = new PathString("/unauthorized/"),
AutomaticAuthenticate = true,
AutomaticChallenge = true
});
Here is my code issuing the creds. 这是我发出证明的代码。
var issuer = SettingBusiness.GetSettingValueAsString("MembersSiteUrl");
var claims = new List<Claim> {new Claim(ClaimTypes.Name, user.UserId.ToString(), ClaimValueTypes.Integer32, issuer)};
var userIdentity = new ClaimsIdentity("MembersUser");
userIdentity.AddClaims(claims);
var userPrincipal = new ClaimsPrincipal(userIdentity);
var authenticationProperties = new AuthenticationProperties
{`enter code here`
ExpiresUtc = DateTime.UtcNow.AddMinutes(60),
IsPersistent = false,
AllowRefresh = true
};
await HttpContext.Authentication.SignInAsync("Cookie", userPrincipal, authenticationProperties);
Having a hard time finding info on this particular scenario. 很难找到有关此特定方案的信息。 Any help would be greatly appreciated.
任何帮助将不胜感激。
I assume this cookie is encrypted with the new data protection system . 我认为此Cookie已使用新的数据保护系统加密。
Your root application will encrypt the cookie with its private key. 您的根应用程序将使用其私钥对cookie进行加密。 Your sub-application currently does not have access to this private key and won't be able to decrypt this cookie.
您的子应用程序当前无权访问此私钥,并且将无法解密此Cookie。
In order for your sub-application to be able to decrypt the cookie, you will need to setup a shared key storage provider . 为了使您的子应用程序能够解密cookie,您将需要设置一个共享密钥存储提供程序 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.