I've created a custom IUserStore<TUser,int>
for my application. I've implemented the interfaces I need,
IUserStore<TUser, int>,
IUserRoleStore<TUser, int>,
IUserLockoutStore<TUser, int>,
IUserPasswordStore<TUser, int>
but when I call
var result = await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, shouldLockout: false);
I get an exception saying
Store does not implement IUserTwoFactorStore<TUser>.
I'm not using two factor authentication anywhere in my application. Why does it expect me to implement that interface? Is it required that I implement all of these interfaces, even if I don't actually use them?
Actually the
IUserTwoFactorStore
interface is really simple, so far my implementation (I don't use two factor auth either) is this:It works, although I just did it couple minutes ago and didn't test whole app thoroughly.
I had the same problem. For the moment, as the SignInManager.SignInOrTwoFactor method blindly checks for the GetTwoFactorAuthentication it throws an exception when the UserStore doesn't implement the IUserTwoFactorStore.
I believe Microsoft intended that the SignInManager PasswordSignInAsync method must be overriden in a custom SignInManager class. Unfortunately I couldn't find any documentation or samples pointing so.
Here is the SignInManager wrapper class I implemented to solve this issue:
I hope it helps. Cheers
I had the same problem and I don't want to implement the
IUserTwoFactorStore<TUser, TKey>
just to say that I don't implement it. But I also don't want to go back and muck around if I end up wanting to implement it (which I anticipate I will). So what I consider a future proof (and reusable) solution would be: (inspired by @gjsduarte's answer)It would probably be a good idea to do the same for the other
Get[feature]EnabledAsync(TKey userId)
methods.