How to implement a TokenProvider in ASP.NET Identity 1.1 nightly build?

后端 未结 4 1304
北海茫月
北海茫月 2021-02-06 06:49

I\'m trying to implement password reset functionality with nightly build of ASP.NET Identity 1.1. There is a UserManager.GetPasswordResetToken method, but it throws an exception

4条回答
  •  醉话见心
    2021-02-06 07:00

    The default token provider implementation is found in the Microsoft.Identity.Owin package:

    /// 
    /// Token provider that uses a DataProtector to generate encrypted tokens
    /// 
    public class DataProtectorTokenProvider : ITokenProvider {
        public DataProtectorTokenProvider(IDataProtector protector)
    

    And you do something like this to wire one up using the default data protection provider from your OWIN IAppBuilder

    IDataProtectionProvider provider = app.GetDataProtectionProvider();
    if (provider != null)
    {
        manager.PasswordResetTokens = new DataProtectorTokenProvider(provider.Create("PasswordReset"));
        manager.UserConfirmationTokens = new DataProtectorTokenProvider(provider.Create("ConfirmUser"));
    }
    

提交回复
热议问题