Generating an Authentication Token with a dynamic Machine Key
I am using the OWIN security context and the CookieAuthenticationProvider to generate authentication cookies:
public partial class Startup {
public void ConfigureAuth(IAppBuilder app) {
app.UseCookieAuthentication(new CookieAuthenticationOptions() {
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Authentication/Login"),
Provider = new CookieAuthenticationProvider()
});
}
}
However, I'd like to implement this in a multi-tenant environment. I already have a tenant context established which has an associated machine key property; I just need a way to generate a token based on a tenant-specific machine key (rather than the machine key in the web.config file).
Ideally, I'd like to inherit and augment the existing OWIN classes (maybe
CookieAuthenticationProvider) rather than implement my own.
Does anyone know how generate an authentication token from a given machine/private key?
Bill
Update
Since Machine keys can't be edited; rather than try to adjust machine keys, would it be secure to implement IDataProtectionProvider or augment DataProtectionProvider to use the System.Security.Cryptography.DpapiDataProtector and pass in a tenant-specific private key as a specificPurpose parameter?
If all tenants shared the machine key but each tenant had their own private key, they wouldn't be able to decrypt each other's authentication tokens, correct?