private async Task<ActionResult> ValidateCode(TwoFactorAuthenticationModel model,
            ClaimsIdentity partialSignInUser)
        {
            var twoFactorTokenService = new TwoFactorTokenService();

            var codeValid = twoFactorTokenService.VerifyTwoFactorCodeFor(
                partialSignInUser.GetSubjectId(), model.Code);
            if (codeValid)
            {
                return Redirect(await GetOwinContext().Environment.GetPartialLoginResumeUrlAsync());
            }

            return View("This code is invalid.");
        }
        private static void PerformTwoFactorAuthentication(PostAuthenticationContext context,
            ClaimsPrincipal authenticatedUser)
        {
            var twoFactorTokenService = new TwoFactorTokenService();
            if (twoFactorTokenService.HasVerifiedTwoFactorCode(authenticatedUser.GetSubjectId()))
            {
                return;
            }

            twoFactorTokenService.GenerateTwoFactorCodeFor(authenticatedUser.GetSubjectId());

            context.AuthenticateResult =
                new AuthenticateResult("~/twofactorauthentication", authenticatedUser.GetSubjectId(),
                    authenticatedUser.GetName(), authenticatedUser.Claims);
        }