Unable to add Token Providers when using multiple Identity Types
My application has two separate identity types. I created two types, as opposed to simply using roles, because the information I have to save about the types are pretty drastically different, and they use two separate applications that act on the same data / database. Plus, these types "interact" with each other. It's sort of like a Business vs Consumer relationship.
I register them like this:
services.AddIdentityCore<UserTypeA>(o =>
{
o.Password.RequireDigit = true;
o.Password.RequireLowercase = false;
o.Password.RequireUppercase = false;
o.Password.RequireNonAlphanumeric = false;
o.Password.RequiredLength = 10;
o.User.RequireUniqueEmail = false;
})
.AddRoles<ApplicationRole>()
services.AddIdentityCore<UserTypeB>(o =>
{
o.Password.RequireDigit = true;
o.Password.RequireLowercase = false;
o.Password.RequireUppercase = false;
o.Password.RequireNonAlphanumeric = false;
o.Password.RequiredLength = 10;
o.User.RequireUniqueEmail = false;
})
.AddRoles<ApplicationRole>()
I don't know if this is the best way to do this, but it's been working fine since this project started. That said, I'm now trying to implement the password reset feature, and I keep getting this error:
"No IUserTwoFactorTokenProvider named 'Default' is registered."
I can add "AddDefaultTokenProviders", but I can't use it on both types. If I put it on both types, I get the same error. If I only put it on one, I can get a token, but only for the type that I've added "AddDefaultTokenProviders" to.
I've looked at the code for AddDefaultTokenProviders and I've seen that it's actually just calling AddTokenProvider. I've tried to implement that directly as well.
I've tried creating a base class that both of my Identity types inherit from and used the services.AddIdentity method to add it to the app and tried to just have one call to AddDefaultTokenProviders. Same issue.
I do feel like there's a pretty good chance that my issues are caused by a flawed design and my use of two identity types in general, but it's been working so far, and I don't know where to go from here.