手动验证ASP.NET Identity中的密码重置令牌

问题描述:

我想手动验证ASP.NET Identity 2.0中的密码重置令牌.我正在尝试创建自己的UserManager.ResetPasswordAsync(string userId, string token, string newPassword)版本,它使用IdentityUserIdentityUser代替userId,如下所示:

I would like to manually validate a password reset token in ASP.NET Identity 2.0. I'm trying to create my own version of UserManager.ResetPasswordAsync(string userId, string token, string newPassword) that takes and IdentityUser instead of userId like this:

UserManager.ResetPasswordAsync(IdentityUser user, string token, string newPassword)

不知道我是否做对了,但是在这里,我试图验证在较早的步骤中通过电子邮件发送给用户的代码.我尚未修改将电子邮件发送给用户并生成代码的代码/令牌.我假设这是调用的正确方法,但是purpose参数不正确. (我尝试传递"ASP.NET身份",但没有骰子.)

Not sure if I am doing this right, but here I am attempting to validate the code that was emailed to the user in an earlier step. I have not modified the code/token that sends the email to the user and generates the code. I am assuming this is the correct method to call, but the purpose argument is incorrect. (I tried passing "ASP.NET Identity" but no dice.)

if (await userManager.UserTokenProvider.ValidateAsync(purpose: "?", token: code, manager: userManager, user: user))
{
    return IdentityResult.Success;
}
else
{
    return new IdentityResult("Invalid code.");
}

如果有人可以开箱即用地填写我的工作细节,或者让我指向Microsoft的UserManager.ResetPasswordAsync(IdentityUser user, string token, string newPassword)源代码,将不胜感激!

If someone could fill me in on the details of how it works out of the box, or point me at Microsoft's source code for UserManager.ResetPasswordAsync(IdentityUser user, string token, string newPassword) that would be most appreciated!

看来,根据位于以下位置的Codeplex存储库,Microsoft.AspNet.Identity的代码尚未开源.

It appears that the code for Microsoft.AspNet.Identity has not been Open Sourced according to the Codeplex repository located at:

https://aspnetidentity.codeplex.com/SourceControl/latest#Readme.markdown

目前,ASP.NET Identity框架代码不是公开的, 因此不会在此网站上发布.但是,我们正在计划 进行更改,我们将尽快发布代码 在此存储库中.

At present, the ASP.NET Identity framework code is not public and therefore will not be published on this site. However, we are planning to change that, and as soon as we are able, the code will be published in this repository.

但是我确实发现了,这可能是基于调试符号的UserManager的来源:

However I did find this which might be the source for the UserManager based on the debug symbols:

我还发现了这些帖子可能会有所帮助:

I also found these posts which might help:

使用ASP.NET Identity实施自定义密码策略

UserManager类文档

IUserTokenProvider接口文档