public async Task <IActionResult> RegisterForMfa(
            RegisterForMfaViewModel model)
        {
            if (ModelState.IsValid)
            {
                // read identity from the temporary cookie
                var resultIdent = await HttpContext.AuthenticateAsync("idsrv.mfa");

                if (resultIdent?.Succeeded != true)
                {
                    throw new Exception("MFA authentication error");
                }
                var subject = resultIdent.Principal.FindFirst(JwtClaimTypes.Subject)?.Value;

                if (await _localUserService.AddUserSecret(subject, "TOTP", model.Secret))
                {
                    await _localUserService.SaveChangesAsync();

                    return(Redirect(model.ReturnUrl));
                }
                else
                {
                    throw new Exception("MFA registration error");
                }
            }
            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> RegisterForMfa(
            RegisterForMfaViewModel model)
        {
            if (ModelState.IsValid)
            {
                var subject = User.FindFirst(JwtClaimTypes.Subject)?.Value;
                if (await _localUserService.AddUserSecret(subject, "TOTP", model.Secret))
                {
                    await _localUserService.SaveChangesAsync();

                    return(Redirect("~/"));
                }
                else
                {
                    throw new Exception("MFA registration error");
                }
            }
            return(View(model));
        }