I'm trying something quite exotic I believe and I'm facing a few problems, which I hope can be solved with the help of the users here on StackOverflow.
The story
I'm writing and application which requires authentication and registration. I've chosen to use Microsoft.AspNet.Identity
. I've not used it a lot in the past, so don't judge me on this decision.
The framework mentioned above contains a users table, that holds all the registered users.
I've created a sample picture to show how the application will be working.
The application consists out of 3 various components:
- Backend (WebAPI).
- Customers (Using the WebAPI directly).
- End Users (Using a Mobile App - iOS).
So, I do have a backend on which Customers can register. There is one unique user per member, so no problem here. A customer is a company here and End Users are cliënts of the company.
You might see the problem already, It's perfectly possible that User 1
is a cliënt at Customer 1
but also at Customer 2
.
Now, a customer can invite a member to use the Mobile application. When a customer does that, the end user does receive an e-mail with a link to active himself.
Now, that's all working fine as long as your users are unique, but I do have a user which is a cliënt of Customer 1
and Customer 2
. Both customers can invite the same user and the user will need to register 2 times, one for each Customer
.
The problem
In Microsoft.AspNet.Identity
framework, users should be unique, which according to my situation, I'm not able to manage.
The question
Is it possible to add extra parameters to the IdentityUser
that make sure a user is unique?
What I've done already
Create a custom class that inherits from
IdentityUser
and which includes an application id:public class AppServerUser : IdentityUser { #region Properties /// <summary> /// Gets or sets the id of the member that this user belongs to. /// </summary> public int MemberId { get; set; } #endregion }
Changed my
IDbContext
accordingly:public class AppServerContext : IdentityDbContext<AppServerUser>, IDbContext { }
Modified calls that are using the framework.
IUserStore<IdentityUser> -> IUserStore<AppServerUser> UserManager<IdentityUser>(_userStore) -> UserManager<AppServerUser>(_userStore);
_userStore
is off course of typeIUserStore<AppServerUser>
However, when I do register a user with a username that is already taken, I still receive an error message saying that the username is already taken:
var result = await userManager.CreateAsync(new AppServerUser {UserName = "testing"}, "testing");
What I do believe is a solution
I do believe that I need to change the UserManager
but I'm not sure about it.
I do hope that someone here has enough knowledge about the framework to help me out because it's really blocking our application development.
If it isn't possible, I would like to know also, and maybe you can point me to another framework that allows me to do this.
Note: I don't want to write a whole user management myself because that will be reïnventing the wheel.