ASP.NET ID - Unable to register UserTokenProvider
I am having a problem generating a password token reset in an ASP.NET Core 1.0 project:
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
...
services.AddIdentity<UserDB, GroupDB>()
.AddDefaultTokenProviders()
}
then in my controller with DI:
...
UserManager<UserDB> userManager
...
string token = await userManager.GeneratePasswordResetTokenAsync(user);
and i get
There is no IUserTokenProvider named Default.
How to fix it?
I see that UserStore
there are no providers inside my constructor :
+3
source to share
1 answer
I noticed that the class UserStore
did not implement the interface implementation IUserTokenProvider
. Also, in the constructor of the class, ApplicationUserManager
I check if theTokenProviderDescriptor
public class ApplicationUserManager : UserManager<UserDB>
{
public ApplicationUserManager(UserStore store, IOptions<IdentityOptions> optionsAccessor, IPasswordHasher<UserDB> passwordHasher, IEnumerable<IUserValidator<UserDB>> userValidators, IEnumerable<IPasswordValidator<UserDB>> passwordValidators, ILookupNormalizer keyNormalizer, IdentityErrorDescriber errors, IServiceProvider services, ILogger<UserManager<UserDB>> logger, IHttpContextAccessor contextAccessor)
: base(store, optionsAccessor, passwordHasher, userValidators, passwordValidators, keyNormalizer, errors, services, logger, contextAccessor)
{
if (!optionsAccessor.Value.Tokens.ProviderMap.ContainsKey("DefaultTokenProvider"))
optionsAccessor.Value.Tokens.ProviderMap.Add("DefaultTokenProvider", new TokenProviderDescriptor(typeof(UserStore)));
}
}
This fixed the problem. Thanks for the help!
+1
source to share