No IUserTwoFactorTokenProvider named \’Default\’ is registered

While working on .NET Core\’s Identity files, I encounter this error: No IUserTwoFactorTokenProvider<TUser> named \’Default\’ is registered.

The Microsoft.AspNetCore.Identity.UserManager<TUser>.GenerateEmailConfirmationTokenAsync or GenerateUserTokenAsync functions couldn\’t generate a token because no provider was available upon registering a new user.

It\’s a very simple fix, just add a little bit more to AddIdentityCore<User> configuration in Startup.cs class services. The fix is to add the AddDefaultTokenProviders().

services.AddIdentityCore<User>(options => 
             {
                 options.Password.RequireNonAlphanumeric = false;
                 options.User.RequireUniqueEmail = true;
                 options.SignIn.RequireConfirmedEmail = true;
                 
             })
             .AddRoles<Role>()
             .AddRoleManager<RoleManager<Role>>()
             .AddSignInManager<SignInManager<User>>()
             .AddRoleValidator<RoleValidator<Role>>()
             .AddEntityFrameworkStores<DataContext>()
             .AddDefaultTokenProviders();

Build the solutions and try again.

Leave a Reply

Scroll to Top
%d bloggers like this: