Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/Idmt.Plugin/Extensions/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,16 @@ private static void ConfigureMultiTenant(IServiceCollection services, IdmtOption

// Enable per-tenant authentication - critical for proper multi-tenant isolation
builder.WithPerTenantAuthentication();


// Isolate Cookies per Tenant
builder.Services.ConfigurePerTenant<CookieAuthenticationOptions, IdmtTenantInfo>(
IdentityConstants.ApplicationScheme, (options, tenantInfo) =>
{
var tenantIdentifier = tenantInfo?.Identifier ?? throw new InvalidOperationException("Tenant information is required to configure cookie options.");
// Prevents Tenant A's tab from overwriting Tenant B's session
options.Cookie.Name = $"{idmtOptions.Identity.Cookie.Name}.{tenantIdentifier}";
});
}

private static void ConfigureIdentity(IServiceCollection services, IdmtOptions idmtOptions)
Expand Down Expand Up @@ -261,7 +271,6 @@ private static void ConfigureAuthentication(
authenticationBuilder.AddIdentityCookies();
services.ConfigureApplicationCookie(options =>
{
options.Cookie.Name = idmtOptions.Identity.Cookie.Name;
options.Cookie.HttpOnly = idmtOptions.Identity.Cookie.HttpOnly;
options.Cookie.SecurePolicy = idmtOptions.Identity.Cookie.SecurePolicy;
options.Cookie.SameSite = idmtOptions.Identity.Cookie.SameSite;
Expand Down