WebSecurity and Multitenancy - how to allow one instance of a username per tenant

42 Views Asked by At

With WebSecurity, Registering a user is like this:

WebSecurity.CreateUserAndAccount(model.UserName, model.Password);

I know I can pass in custom parameters for my User table as well. What I'm wondering is - in a multi-tenant scenario, how do I allow WebSecurity to enforce uniqueness on Username and TenantId columns, instead of just Username?

Related - when logging in, how do I specify a `TenantId' so that forms auth assigns a cookie only if the user exists on the specified tenant?

Unfortunately I can only extend WebSecurity and don't have the option to replace it. Hopefully there's a way to make this work.

1

There are 1 best solutions below

0
Robba On

We've solved this problem in the past by just adding a tenant identifier to the username when saving the user and again when verifying the login credentials.

The user doesn't see this, but it works brilliantly and easily!