I'm trying to implement multi tenancy based on the first folder segment of the request url. In order to isolate cookies between the tenants I'm trying to configure them with different names but I'm having a hard time figuring out how to do it. Currently my code is like this:
foreach (SiteFolder f in allFolders)
{
PathString path = new PathString("/" + f.FolderName);
app.Map(path,
siteApp =>
{
// this commented line would normally configure the cookies but I'm trying to do it myself below
//siteApp.UseIdentity();
siteApp.UseCookieAuthentication(options =>
{
options.LoginPath = new PathString("/" + f.FolderName + "/Account/Login");
options.LogoutPath = new PathString("/" + f.FolderName + "/Account/LogOff");
options.CookieName = f.FolderName + "-ext";
options.SlidingExpiration = true;
},
IdentityOptions.ExternalCookieAuthenticationScheme
);
siteApp.UseCookieAuthentication(options =>
{
options.LoginPath = new PathString("/" + f.FolderName + "/Account/Login");
options.LogoutPath = new PathString("/" + f.FolderName + "/Account/LogOff");
options.CookieName = f.FolderName + "-tfr";
options.SlidingExpiration = true;
},
IdentityOptions.TwoFactorRememberMeCookieAuthenticationScheme
);
siteApp.UseCookieAuthentication(options =>
{
options.LoginPath = new PathString("/" + f.FolderName + "/Account/Login");
options.LogoutPath = new PathString("/" + f.FolderName + "/Account/LogOff");
options.CookieName = f.FolderName + "-tf";
options.SlidingExpiration = true;
},
IdentityOptions.TwoFactorUserIdCookieAuthenticationScheme
);
siteApp.UseCookieAuthentication(options =>
{
options.LoginPath = new PathString("/" + f.FolderName + "/Account/Login");
options.LogoutPath = new PathString("/" + f.FolderName + "/Account/LogOff");
options.CookieName = f.FolderName + "-app";
options.SlidingExpiration = true;
},
IdentityOptions.ApplicationCookieAuthenticationScheme
);
});
}
but none of the options including the cookie name I'm changing seem to have any effect.
I'm also a little confused because some things in Identity get "configured" by dependency injection rather than by IApplicationBuilder. I would expect that things previously configured by DI would be just defaults thaT could be changed later by IApplicationBuilder but it isn't clear to me how.
Can anyone shed any light on how to alter things such as cookie name when using Identity?