简体   繁体   中英

Custom UserConfirmation not being called in Asp.Net Core 5 Identity

Using Asp.Net Core 5.0 I am adding Identity and a custom UserConfirmation:

  services
    .AddIdentityCore<User>()
    .AddEntityFrameworkStores<Context>()
    .AddDefaultTokenProviders()
    .AddUserConfirmation<UserConfirmation<User>>();

Where my custom UserConfirmation is the following:

  public class UserConfirmation<T> : IUserConfirmation<T> where T : User {

    public async virtual Task<Boolean> IsConfirmedAsync(UserManager<T> manager, T user) {
      
      if (!user.Enabled)
        return false;

      if (!await manager.IsEmailConfirmedAsync(user)) 
        return false;
      
      return true;

    }

  }

However the method CanSignInAsync :

_signInManager.CanSignInAsync(user)

returns always true even with user is not enabled.

And the breakpoint I added in IsConfirmedAsync is not being triggered.

What am I missing?

I found the problem. The following needs to be added to Identity options:

services.AddIdentityCore<User>(options => {
  options.SignIn.RequireConfirmedAccount = true;
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM