Пример #1
0
        public async Task <ActionResult> ResetPasswordAsync(ResetPasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("ResetPassword", model));
            }

            try
            {
                var authResponse = await _oktaAuthenticationClient.ResetPasswordAsync(
                    new ResetPasswordOptions()
                {
                    NewPassword = model.NewPassword,
                    StateToken  = Session["stateToken"].ToString(),
                }).ConfigureAwait(false);

                if (authResponse.AuthenticationStatus == AuthenticationStatus.Success)
                {
                    var username = authResponse.Embedded
                                   .GetProperty <Resource>("user")
                                   .GetProperty <Resource>("profile")
                                   .GetProperty <string>("login");

                    var identity = new ClaimsIdentity(
                        new[] { new Claim(ClaimTypes.Name, username) },
                        DefaultAuthenticationTypes.ApplicationCookie);

                    _authenticationManager.SignIn(new AuthenticationProperties {
                        IsPersistent = (bool)Session["rememberMe"]
                    }, identity);

                    return(RedirectToAction("Index", "Home"));
                }

                throw new NotImplementedException($"Unhandled Authentication Status {authResponse.AuthenticationStatus}");
            }
            catch (Exception exception)
            {
                ModelState.AddModelError(string.Empty, exception.Message);
                return(View("ResetPassword", model));
            }
        }