我有一个多租户申请。每个租户都可以使用OAUTH-2使用Facebook、Twitter、Google等对用户进行身份验证。每个租户都有自己的上述服务的API密钥。
安装OWIN管道的典型方法是在启动时“使用”auth提供程序,但这会在app启动时设置API键。我需要能够更改每个请求与每个oauth一起使用的键。
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
Provider = cookieAuthProvider,
CookieName = "VarsityAuth",
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
app.UseMicrosoftAccountAuthentication(
clientId: "lkjhlkjkl",
clientSecret: "kjhjkk");我需要能够根据租户的每个请求更改这些设置。我该怎么做?
发布于 2014-10-23 18:05:49
编辑-我现在可以确认这个解决方案正在为我工作。
我正在为我自己的项目研究这个问题,它需要根据主机名或请求的第一个文件夹段(取决于配置)支持多个租户。
我还没有对其进行测试,但我认为在启动时这样的代码可能会奏效:
例如,我想为每个租户使用一个不同的auth cokie名称,并且我认为在启动时使用类似这样的代码是可行的:
// for first folder segment represents the tenant
app.Map("/branch1", app1 =>
{
app1.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<SiteUserManager, SiteUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
},
CookieName = "branch1-app"
});
});
// for when the host name of the request identifies the tenant
app.MapWhen(IsDomain1, app2 =>
{
app2.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<SiteUserManager, SiteUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
},
CookieName = "domain1-app"
});});
private bool IsDomain1(IOwinContext context)
{
return (context.Request.Host.Value == "domain1");
}https://stackoverflow.com/questions/25393234
复制相似问题