Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does CanSignInAsync(xyz) method of SignInManager work?

In ASP.NET Core Identity, how does CanSignInAsync(xyz) method of SignInManager work, what's it's real purpose, and what methods of the custom store provider interfaces (e.g. IUserStore) implementations does it hit?

like image 231
Olumide Avatar asked Oct 24 '25 21:10

Olumide


1 Answers

From source code of CanSignInAsync(TUser) Method, we can find this method can help check if the specified user can sign in based on confirmation status, like below.

public virtual async Task<bool> CanSignInAsync(TUser user)
{
    if (Options.SignIn.RequireConfirmedEmail && !(await UserManager.IsEmailConfirmedAsync(user)))
    {
        Logger.LogWarning(0, "User {userId} cannot sign in without a confirmed email.", await UserManager.GetUserIdAsync(user));
        return false;
    }
    if (Options.SignIn.RequireConfirmedPhoneNumber && !(await UserManager.IsPhoneNumberConfirmedAsync(user)))
    {
        Logger.LogWarning(1, "User {userId} cannot sign in without a confirmed phone number.", await UserManager.GetUserIdAsync(user));
        return false;
    }
    if (Options.SignIn.RequireConfirmedAccount && !(await _confirmation.IsConfirmedAsync(UserManager, user)))
    {
        Logger.LogWarning(4, "User {userId} cannot sign in without a confirmed account.", await UserManager.GetUserIdAsync(user));
        return false;
    }
    return true;
}
like image 72
Fei Han Avatar answered Oct 27 '25 01:10

Fei Han



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!