NotSupportedException No IUserTwoFactorTokenProvider<TUser> named 'Default' is registered

While modifying .NET Core's Identity files, I stumbled upon this error: NotSupportedException: No IUserTwoFactorTokenProvider<TUser> named 'Default' is registered.

The Microsoft.AspNetCore.Identity.UserManager<TUser>.GenerateUserTokenAsync function couldn't generate a token because no provider was available upon registering a new user. This error has an easy fix though!

If you're like me, you changed AddDefaultIdentity in the Startup.cs file to AddIdentity. I wanted to implement my own user that inherited from the base user. By doing this I lost the default token providers. The fix was to add them back with AddDefaultTokenProviders().

            services.AddIdentity<User, UserRole>()
                .AddEntityFrameworkStores<ApplicationDbContext>()
                .AddDefaultTokenProviders();

After that fix, everything worked again!

Matt Ferderer

Full Stack Software Developer focused on JavaScript and C#. Love to share & help others make amazing things. Have a project you need help on? Let's talk!

comment

Comments