How to fix IUserTwoFactorTokenProvider<TUser> error

Published on

I recently experienced the NotSupportedException: No IUserTwoFactorTokenProvider<TUser> named 'Default' is registered error when trying to update a user and generate a password reset token via ASP.NET 5 Identity. This problem likely also exists in ASP.NET Core too.

It turns out that this error is caused by a missing provider for the identity system.

You can fix the problem by making a small change within the ConfigureServices method inside Startup.cs.

I just had to add .AddEntityFrameworkStores<ApplicationDbContext>() and .AddDefaultTokenProviders() to my identity provider.

            services.AddIdentity<IdentityUser, IdentityRole>(options => options.SignIn.RequireConfirmedAccount = true)
                .AddRoles<IdentityRole>()
                .AddEntityFrameworkStores<ApplicationDbContext>()
                .AddDefaultTokenProviders();

And that's it, an extremely easy fix. You just need to rebuild the solution and try again after making the change.


Article Categories: # .net # c# # identity
Date Published: Aug 15, 2020

About

A tech blog by Andy P. I talk about coding, enterprise software development, tech, games design & other things that interest me.

Teambuilding & fitness

Our friends at Company Fitness League are building fun platform for getting fit with your colleagues!