Asp Identity 2 - Change Expiry Time for Mobile Token

前端 未结 2 1964
鱼传尺愫
鱼传尺愫 2021-01-29 05:43

I have the following code that ensures the Token lifetime span for email verification tokens expire after 14 days :-

if (Startup.DataProtectionProvider != null)
         


        
2条回答
  •  后悔当初
    2021-01-29 06:03

    If you don't want to override the UserManager class, you can always grab the token after creation and adjust the ExpirationDate manually. For example, we do this in our e-mail sending logic (always refresh the token for another 24 hours if you re-send the e-mail):

    // Token already created
    UserToken userToken = db.UserTokens.Where(t => t.UserId == user.Id && f.IsActive).FirstOrDefault();
    userToken.ExpirationDate = DateTime.Now.AddHours(24);
    

提交回复
热议问题