【发布时间】:2015-04-08 14:50:25
【问题描述】:
我们将多租户 MVC 应用程序从 ASP.NET Membership Provider 迁移到 ASP.NET Identity。
这是我的 Startup.Auth.cs(简化版):
public partial class Startup
{
public void ConfigureAuth(IAppBuilder app)
{
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity =
SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, Identity, int>(
TimeSpan.FromMinutes(30),
(manager, user) =>
manager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie),
clIdentity => clIdentity.GetUserId<int>())
}
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
}
在我们的多租户应用程序中,每个租户都有自己的“slug”(例如http://example.com/tenant1/ 和http://example.com/tenant2/)
但是,目前,cookie 存储在根目录中。这会导致安全问题,因为租户 1 的用户会自动从租户 2 登录网站。
我们如何使 CookiePath(在 CookieAuthenticationOptions 中)变量,以便它根据租户而改变?
【问题讨论】:
标签: cookies asp.net-identity owin