Build a custom user check password in Asp.Net Identity 2

懵懂的女人 提交于 2019-12-04 10:53:23

It should work. I've just used the standard ASP.NET MVC template, updated all the libraries involved through NuGet, and it must work.

I guess the problems is the way you are overriding the method.

In your ApplicationUserManager try to change your code like this:

public override Task<bool> CheckPasswordAsync(ApplicationUser user, string password)
{
    return Task.FromResult<bool>(true);
}

or:

public override Task<bool> CheckPasswordAsync(ApplicationUser user, string password)
{
    return Task.Run(() => MyCheckPasswordAsync());
}

private bool MyCheckPasswordAsync()
{
    return true;
}

and you will see it goes through:

The problem was that I was trying to login with a user that do not exists in the system.

The SignInManager.PasswordSignInAsync never invoke the ApplicationUserManager. CheckPasswordAsync if the user not exists in the user store repository.

In conclusion, I have to store the users in my application or implement a custom user store mechanism.

This may not be a direct answer however it provides a full solution to the problem. He implements a custom authorisation filter which you can then customise to do what you want.

https://weblog.west-wind.com/posts/2013/Apr/18/A-WebAPI-Basic-Authentication-Authorization-Filter

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false)]
public class BasicAuthenticationFilter : AuthorizationFilterAttribute

It can then be used like this instead of the [Authorize] attribute

[MyBasicAuthenticationFilter]
public class QueueController : ApiController
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!