The store does not implement IUserLockoutStore <TUser>

I am trying to implement my own DAL for asp.net Identity 2.0 with the functionality I need. I do not need account lockout features. But when I try to call

var result = await SignInManager.PasswordSignInAsync(model.Login, model.Password, model.RememberMe, shouldLockout: false); 

I get a System.NotSupportedException:Store does not implement IUserLockoutStore<TUser>.

So why do I need to implement IUserLockoutStore if I don't need it?

+7
asp.net-mvc-5 asp.net-identity
source share
1 answer

See this answer: When implementing your own IUserStore are "optional." Are interfaces in the class really optional?

You will need to trick or override the method that you are trying to call in your store to implement one that does not use the "optional" store lock.

You may be pleasantly surprised to find that you also need to implement an β€œadditional” two-factor interface. Use the same answer below to do this if you do not have a two-factor device.

Firstly, the default implementation is implemented here:

 public virtual async Task<SignInStatus> PasswordSignInAsync(string userName, string password, bool isPersistent, bool shouldLockout) { ... if (await UserManager.IsLockedOutAsync(user.Id).WithCurrentCulture()) { return SignInStatus.LockedOut; } if (await UserManager.CheckPasswordAsync(user, password).WithCurrentCulture()) { return await SignInOrTwoFactor(user, isPersistent).WithCurrentCulture(); } ... return SignInStatus.Failure; } 

One answer: create useless stores.

  #region LockoutStore public Task<int> GetAccessFailedCountAsync(MyUser user) { throw new NotImplementedException(); } public Task<bool> GetLockoutEnabledAsync(MyUser user) { return Task.Factory.StartNew<bool>(() => false); } public Task<DateTimeOffset> GetLockoutEndDateAsync(MyUser user) { throw new NotImplementedException(); } public Task<int> IncrementAccessFailedCountAsync(MyUser user) { throw new NotImplementedException(); } public Task ResetAccessFailedCountAsync(MyUser user) { throw new NotImplementedException(); } public Task SetLockoutEnabledAsync(MyUser user, bool enabled) { throw new NotImplementedException(); } public Task SetLockoutEndDateAsync(MyUser user, DateTimeOffset lockoutEnd) { throw new NotImplementedException(); } #endregion } 

Another solution: override, just to not use it.

 public virtual async Task<SignInStatus> PasswordSignInAsync(string userName, string password, bool isPersistent, bool shouldLockout) { ... if (false) { return SignInStatus.LockedOut; } if (await UserManager.CheckPasswordAsync(user, password).WithCurrentCulture()) { return await SignInOrTwoFactor(user, isPersistent).WithCurrentCulture(); } ... return SignInStatus.Failure; } 

cf / http://eliot-jones.com/Code/asp-identity/MyUserStore.cs

+10
source share

All Articles