1.1.0-alpha
Pre-releaseAdded support for tenant middleware pipelines.
The main purpose of this feature is to enable ASP.NET Authentication middleware to be used in multi-tenant applications. As described in this GitHub issue, most of the ASP.NET Auth middleware components require their options to be specified at the time the middleware is registered. This is a problem in multi-tenant applications since it means every tenant must have the same configuration e.g. all tenants use the same Google API keys.
This release adds the UsePerTenant extension to IApplicationBuilder which enables forked middleware pipelines to be created per tenant, thus allowing the authentication middleware to be configured per tenant:
app.UsePerTenant<AppTenant>((ctx, builder) =>
{
builder.UseCookieAuthentication(options =>
{
options.AuthenticationScheme = "Cookies";
options.LoginPath = new PathString("/account/login");
options.AccessDeniedPath = new PathString("/account/forbidden");
options.AutomaticAuthenticate = true;
options.AutomaticChallenge = true;
options.CookieName = $"{ctx.Tenant.Id}.AspNet.Cookies";
});
builder.UseGoogleAuthentication(options =>
{
options.AuthenticationScheme = "Google";
options.SignInScheme = "Cookies";
options.ClientId = Configuration[$"{ctx.Tenant.Id}:GoogleClientId"];
options.ClientSecret = Configuration[$"{ctx.Tenant.Id}:GoogleClientSecret"];
});
});
It's highly recommended that your tenant class implements IEquatable<TTenant> to avoid potential possible race conditions when resolving tenants, as per https://github.com/saaskit/saaskit/blob/master/samples/AspNetMvcAuthDemo/AppTenant.cs.
For more details please see this blog post.