Exemple #1
0
        public async Task <ActionResult> Index(TwoFactorAuthenticationModel model)
        {
            // we're only allowed here when we have a partial sign-in
            var ctx = Request.GetOwinContext();
            var partialSignInUser = await ctx.Environment.GetIdentityServerPartialLoginAsync();

            if (partialSignInUser == null)
            {
                return(View("No partially signed-in user found."));
            }

            if (ModelState.IsValid)
            {
                using (var twoFactorTokenService = new TwoFactorTokenService())
                {
                    if (twoFactorTokenService.VerifyTwoFactorCodeFor(partialSignInUser.GetSubjectId(), model.Code))
                    {
                        // continue where we left off
                        return(Redirect(await ctx.Environment.GetPartialLoginResumeUrlAsync()));
                    }
                    else
                    {
                        // show error
                        return(View("This code is invalid."));
                    }
                }
            }

            return(View());
        }
Exemple #2
0
        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."));
        }