IdsvrMultiTenantExample
IdsvrMultiTenantExample copied to clipboard
ASP.NET Core 2 support
Because of changes since ASP.NET Core 1.1 times, this code won't work on 2.0.
What's your opinion on getting it upgraded? Is there really a need or should we stick to ASP.NET Core 1.1 and IdentityServer4 (v.1.5.2), at least for the Identity Service piece, for the long run?
app.Map("/tenants", multiTenantIdsvrMountPoint =>
{
// Saaskit.Multitenancy
multiTenantIdsvrMountPoint.UseMultitenancy<SwioTenant>();
multiTenantIdsvrMountPoint.UsePerTenant<SwioTenant>((ctx, builder) =>
{
var mountPath = "/" + ctx.Tenant.Name.ToLowerInvariant();
// we mount the tenant specific IdSvr4 app under /tenants/<tenant>/
builder.Map(mountPath, idsvrForTenantApp =>
{
var identityServerOptions = idsvrForTenantApp.ApplicationServices.GetRequiredService<IdentityServerOptions>();
// we use our own cookie middleware because Idsvr4 expects it to be included in the
// pipeline as we have changed the default authentication scheme
idsvrForTenantApp.UseCookieAuthentication(new CookieAuthenticationOptions()
{
AuthenticationScheme = identityServerOptions.Authentication.AuthenticationScheme,
CookieName = identityServerOptions.Authentication.AuthenticationScheme,
AutomaticAuthenticate = true,
SlidingExpiration = false,
ExpireTimeSpan = TimeSpan.FromHours(10)
});
idsvrForTenantApp.UseIdentityServer();
idsvrForTenantApp.UseMvc(routes =>
{
routes.MapRoute(name: "Account",
template: "account/{action=Index}",
defaults: new { controller = "Account" });
});
});
});
});
Would be very interested to get this working in 2.0.
I've done a quick fork on saaskit to get it working on netcoreapp2.0
Sincebuilder.UseCookieAuthentication(new CookieAuthenticationOptions
is Obsolete, I am trying to obtain the same effect using a set of transient services that overwrite the configuration every time it is needed.
See the PR here: https://github.com/saaskit/saaskit/pull/96 and let me know what you think.