aspnet / Identity

[Archived] ASP.NET Core Identity is the membership system for building ASP.NET Core web applications, including membership, login, and user data. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
1.96k stars 866 forks source link

Missing the UserManager.VerifyPasswordResetTokenAsync method #1320

Closed MovGP0 closed 7 years ago

MovGP0 commented 7 years ago

I want to implement a password change flow. Naturally I would expect it to work like this:

var token = await UserManager.GeneratePasswordResetTokenAsync(user);
var result = await UserManager.VerifyPasswordResetTokenAsync(user, token);

Unfortunately, I only find this method:

var result = await UserManager.VerifyUserTokenAsync(user, "tokenProvider", "ResetPassword", token);

This makes it confusing what to use as token provider and purpose strings. Allowing to use custom token providers and purposes seems like a good idea, but when just starting out, there should be a default implementation.

MovGP0 commented 7 years ago

Implementation is pretty straight-forward:

public async virtual Task<bool> VerifyChangePasswordTokenAsync(TUser user, string token)
{
     var tokenProvider = Options.Tokens.PasswordResetTokenProvider;
     return await VerifyUserTokenAsync(user, tokenProvider, "ResetPassword", token);
}
HaoK commented 7 years ago

You are looking for the ResetPassword method I believe:

https://github.com/aspnet/Identity/blob/dev/src/Microsoft.Extensions.Identity.Core/UserManager.cs#L862

MovGP0 commented 7 years ago

No I don't. I want to implement the token verification.

blowdart commented 7 years ago

This was a deliberate design choice, to avoid the weird intermediate state of verifying a token, but not using it for an action. Your work around is correct, but its unlikely the flow/api will change, unless we get more people asking for this.

sanmscse commented 6 years ago

Hi,

What value we have to set for _userManager.Options.Tokens.AuthenticatorTokenProvider.

I'm using 2FA without Entity Framework in core2.0. i've to write custom methods for token generation and verification. the below method reuires string for AuthenticatorTokenProvider. Does anyone know what provider i'veto give?

var is2faTokenValid = await _userManager.VerifyTwoFactorTokenAsync( user, _userManager.Options.Tokens.AuthenticatorTokenProvider, verificationCode);

Thanks, Saravanan