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

后端 未结 4 1298
北海茫月
北海茫月 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:16

    Another way to do this (building on the other answers but simplifying it some) is to change Startup.Auth.cs so it looks similar to this:

    public partial class Startup
    {
        internal static IDataProtectionProvider DataProtectionProvider { get; private set; }
    
        public void ConfigureAuth(IAppBuilder app)
        {
            DataProtectionProvider = app.GetDataProtectionProvider();
        }
    }
    

    Then, modify the default constructor in AccountController.cs so that it looks similar to this:

     public AccountController()
         : this(new UserManager(new UserStore(new ApplicationDbContext())))
     {
         if (Startup.DataProtectionProvider != null)
         {
             this.UserManager.PasswordResetTokens = new DataProtectorTokenProvider(Startup.DataProtectionProvider.Create("PasswordReset"));
             this.UserManager.UserConfirmationTokens = new DataProtectorTokenProvider(Startup.DataProtectionProvider.Create("ConfirmUser"));
         }
     }
    

提交回复
热议问题