I have a working Asp.Net Core application with default Identity handling. Now I want to use it for multi domains. I extended ApplicationUser with DomainId. How can I handle not just username / email to authenticate / register the user, but also the current DomainId?
It's not a problem to get the current DomainId when the user is registering, logging into the system, I have a working multi-tenant Asp.Net Core system. I have issue only with user management with DomainId.
Is there any setting for this? What should I override to get this funcionality? For example UserStore, UserManager?
I found some tutorial for old Asp.Net Identity for example this: https://www.scottbrady91.com/ASPNET-Identity/Quick-and-Easy-ASPNET-Identity-Multitenancy But I couldn't find any tutorial for the new Asp.Net Core Identity.
Finally I figured it out. So first, I have to set user email to not unique. Sidenote: I'm using email for UserName also, I don't like to ask UserName from users:
When a new user register himself, I'm merging current Domain Id to UserName, this helps users to register with same Email / UserName into the system through totally different domains.
Then I had to create my custom UserManager, where I'm overriding FindByEmail:
Be careful, because of multi-domains and generated UserNames, you should use userManager.FindByEmailAsync, instead of FindByNameAsync.
I had to create custom SignInManager for handling multi-domain users:
Finally I have to register my custom managers into Asp.Net Core Identity DI:
That's it!