c# - ASP.NET Identity - can't register UserTokenProvider -
i have issue generating reset password token in asp.net core 1.0 project:
startup.cs
public void configureservices(iservicecollection services) { ... services.addidentity<userdb, groupdb>() .adddefaulttokenproviders() }
then in controller di:
... usermanager<userdb> usermanager ... string token = await usermanager.generatepasswordresettokenasync(user);
and
no iusertokenprovider named 'default' registered.
how fix ?
i can see there's no providers inside of userstore
constructor:
i noticed userstore
class didn't have iusertokenprovider
interface implementation. also, in applicationusermanager
class constructor, check if tokenproviderdescriptor
registered
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))); } }
that's solved issue. !
Comments
Post a Comment