identity: reset user 2fa on password reset
This commit is contained in:
@@ -302,6 +302,7 @@ namespace Streetwriters.Identity.Controllers
|
|||||||
var result = await UserManager.RemovePasswordAsync(user);
|
var result = await UserManager.RemovePasswordAsync(user);
|
||||||
if (result.Succeeded)
|
if (result.Succeeded)
|
||||||
{
|
{
|
||||||
|
await MFAService.ResetMFAAsync(user);
|
||||||
result = await UserManager.AddPasswordAsync(user, form.NewPassword);
|
result = await UserManager.AddPasswordAsync(user, form.NewPassword);
|
||||||
if (result.Succeeded)
|
if (result.Succeeded)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ namespace Streetwriters.Identity.Interfaces
|
|||||||
{
|
{
|
||||||
Task EnableMFAAsync(User user, string primaryMethod);
|
Task EnableMFAAsync(User user, string primaryMethod);
|
||||||
Task<bool> DisableMFAAsync(User user);
|
Task<bool> DisableMFAAsync(User user);
|
||||||
|
Task<bool> ResetMFAAsync(User user);
|
||||||
Task SetSecondaryMethodAsync(User user, string secondaryMethod);
|
Task SetSecondaryMethodAsync(User user, string secondaryMethod);
|
||||||
string GetPrimaryMethod(User user);
|
string GetPrimaryMethod(User user);
|
||||||
string GetSecondaryMethod(User user);
|
string GetSecondaryMethod(User user);
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ namespace Streetwriters.Identity.Services
|
|||||||
if (!result.Succeeded) return;
|
if (!result.Succeeded) return;
|
||||||
|
|
||||||
await this.RemovePrimaryMethodAsync(user);
|
await this.RemovePrimaryMethodAsync(user);
|
||||||
|
await this.RemoveSecondaryMethodAsync(user);
|
||||||
await UserManager.AddClaimAsync(user, new Claim(MFAService.PRIMARY_METHOD_CLAIM, primaryMethod));
|
await UserManager.AddClaimAsync(user, new Claim(MFAService.PRIMARY_METHOD_CLAIM, primaryMethod));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,6 +70,20 @@ namespace Streetwriters.Identity.Services
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<bool> ResetMFAAsync(User user)
|
||||||
|
{
|
||||||
|
var result = await UserManager.SetTwoFactorEnabledAsync(user, false);
|
||||||
|
var result = await UserManager.SetTwoFactorEnabledAsync(user, true);
|
||||||
|
|
||||||
|
await this.RemovePrimaryMethodAsync(user);
|
||||||
|
await this.RemoveSecondaryMethodAsync(user);
|
||||||
|
|
||||||
|
await UserManager.AddClaimAsync(user, new Claim(MFAService.PRIMARY_METHOD_CLAIM, MFAMethods.Email));
|
||||||
|
|
||||||
|
await UserManager.ResetAuthenticatorKeyAsync(user);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public async Task SetSecondaryMethodAsync(User user, string secondaryMethod)
|
public async Task SetSecondaryMethodAsync(User user, string secondaryMethod)
|
||||||
{
|
{
|
||||||
await this.ReplaceClaimAsync(user, MFAService.SECONDARY_METHOD_CLAIM, secondaryMethod);
|
await this.ReplaceClaimAsync(user, MFAService.SECONDARY_METHOD_CLAIM, secondaryMethod);
|
||||||
|
|||||||
Reference in New Issue
Block a user