ApplicationUserManager的Generate ___ Token方法 [英] ApplicationUserManager's Generate ___ Token methods

查看:160
本文介绍了ApplicationUserManager的Generate ___ Token方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到ApplicationUserManager上有5种不同的Generate Token方法,例如:

I see there are 5 different Generate Token methods on ApplicationUserManager such as:

  • 经理. GenerateChangePhoneNumberToken ()
  • 经理. GenerateEmailConfirmationToken ()
  • 经理. GeneratePasswordResetToken ()
  • 经理. GenerateTwoFactorToken ()
  • 管理员. GenerateUserToken ()
  • manager.GenerateChangePhoneNumberToken()
  • manager.GenerateEmailConfirmationToken()
  • manager.GeneratePasswordResetToken()
  • manager.GenerateTwoFactorToken()
  • manager.GenerateUserToken()

当其他四个存在时,GenerateUserToken有什么意义?什么时候只使用GenerateUserToken而不使用其他任何人?

What is the point of GenerateUserToken when the other 4 exist? When would you only use GenerateUserToken and not any of the others?

是否可以将GenerateUserToken中的UserToken代替其他4个用于所有可能的令牌请求任务?

Can the UserToken from GenerateUserToken be used instead of the other 4 for all possible token requested tasks?

试图更好地理解这些内容,但没有通过搜索找到太多帮助.谢谢!

Trying to understand these better but not finding much help through searching. Thanks!

推荐答案

如果您查看

If you look on the source code of UserManager, you'll see that GenerateUserTokenAsync(string purpose, TKey userId) is the one with most logic. All other methods you talk about are a shortcuts for this method with parameter purpose specified.

因此,当您需要重设密码时,请呼叫GeneratePasswordResetTokenAsync(TKey userId),然后依次呼叫GenerateUserTokenAsync("ResetPassword", userId).

So when you need to reset password you call GeneratePasswordResetTokenAsync(TKey userId) that in turn calls GenerateUserTokenAsync("ResetPassword", userId).

purpose参数编码在令牌中,并且在返回途中,当验证令牌时,此目的必须与生成令牌时的目的相同. IE.为密码重置而生成的令牌无法用于电子邮件确认.

This purpose parameter is encoded in the token and on the way back, when the token is verified, this purpose must be the same as it was for token generation. I.e. token generated for password reset will not work for email confirmation.

这篇关于ApplicationUserManager的Generate ___ Token方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆