documentation is lacking the final steps for member access when two factor authentication is enabled.
Using:
Umbraco 13.2.0
Microsoft.aspnetcore.authentication.google version 7.0.13
I have successfully followed the documentation for the users and add it there but the members area is lacking the actual login procedure for the front end.
1 have created a page with the qr code to scan with google authenticator. and verified it with the verification process. And this all creates correctly.
This was all done following this documentation https://docs.umbraco.com/umbraco-cms/v/12.latest/reference/security/two-factor-authentication
However the documentation falls shot of explaining the process to verify codes when the member is logging in.
IMember member = _memberService.GetByUsername(model.Username);
// Tests and processes logins where Two factor is not enabled -- works fine
if (!(await _twoFactorLoginService.IsTwoFactorEnabledAsync(member.Key))) {
.................
}
// Checks that the user name and password are correct if so hide username password and show verification code input -- works fine
else if (string.IsNullOrEmpty(model.Code) &&
await _memberManager.ValidateCredentialsAsync(model.Username, model.Password))
{
TempData.Add("LoginCredentials_" + model.UniqueID, "hidden");
return (IActionResult)RedirectToCurrentUmbracoPage();
}
else
{
// get the used details
MemberIdentityUser userIdentity = await _memberManager.FindByNameAsync(model.Username);
// gets the two auth provider name
var providerID = _twoFactorLoginService.GetEnabledTwoFactorProviderNamesAsync(_memberService.GetAllMembers().FirstOrDefault(x => x.Username == model.Username).Key);
var providerName = providerID.Result.First();
if (userIdentity != null)
{
var result = await _memberSignInManager.TwoFactorSignInAsync(
providerName,
model.Code,
false,
true);
if (result.Succeeded) // always fails
{
return Redirect(model.ReturnUrl);
}
}
}
Always fails at the final step to verify the code.
This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/113798-two-factor-authentication-for-members