I'm trying to do something quite exotic, I believe, and run into a few problems that I hope can be solved with the help of users here on StackOverflow.
History
I am writing and an application that requires authentication and registration. I decided to use Microsoft.AspNet.Identity . I have not used it a lot in the past, so do not judge me by this decision.
The structure above contains a user table in which all registered users are stored.
I created a sample image to show how the application will work.

The application consists of three different components:
- Backend (WebAPI).
- Clients (directly using WebAPI).
- End users (using a mobile application - iOS).
So, I have a backend where clients can register. There is one unique user for each member, so there is no problem. The customer is the company here, and End users are the clicks of the company.
You may already see the problem. It is entirely possible that User 1 is a customer in Customer 1 , but also in Customer 2 .
Now the client can invite the participant to use the mobile application. When the client does this, the end user receives an email with a link for the active user.
Now everything works fine, as long as your users are unique, but I have a user who is a customer of Customer 1 and Customer 2 . Both clients can invite the same user, and the user will need to register 2 times, one for each Customer .
Problem
Within Microsoft.AspNet.Identity users must be unique, which, according to my situation, I canβt manage.
Question
Can I add additional parameters to IdentityUser to make sure the user is unique?
What i have already done
Create your own class that inherits from IdentityUser and which includes the application identifier:
public class AppServerUser : IdentityUser { #region Properties
Changed my IDbContext accordingly:
public class AppServerContext : IdentityDbContext<AppServerUser>, IDbContext { }
Modified calls that use the framework.
IUserStore<IdentityUser> -> IUserStore<AppServerUser> UserManager<IdentityUser>(_userStore) -> UserManager<AppServerUser>(_userStore);
_userStore disconnected from type IUserStore<AppServerUser>
However, when I register a user with an already accepted username, I still get an error message stating that the username has already been executed:
var result = await userManager.CreateAsync(new AppServerUser {UserName = "testing"}, "testing");
What I believe is a solution
I really believe that I need to change the UserManager , but I'm not sure about that. I hope someone here has enough knowledge about the structure to help me, because it really blocks the development of our application.
If this is not possible, I would also like to know, and perhaps you can point me to another structure that allows me to do this.
Note. . I do not want to write all user management myself, because it will overwrite the wheel.