Custom ASP.NET Identity 2.0 UserStore - Is implementing all interfaces required?

Stephen Collins picture Stephen Collins · Aug 28, 2014 · Viewed 11.4k times · Source

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?

Answer

Ignas Vyšnia picture Ignas Vyšnia · Dec 2, 2014

Actually the IUserTwoFactorStore interface is really simple, so far my implementation (I don't use two factor auth either) is this:

 ....
 public Task<bool> GetTwoFactorEnabledAsync(User user)
 {
     return Task.FromResult(false);
 }

 public Task SetTwoFactorEnabledAsync(User user, bool enabled)
 {
     throw new NotImplementedException();
 }

It works, although I just did it couple minutes ago and didn't test whole app thoroughly.