private void CheckPassword(string login, string password) { ResetErrors(); try { AuthResponse result = Factory.AuthnClient.Authenticate(login, password); if (string.IsNullOrEmpty(result.SessionToken)) { //todo: error handling ShowError($"Login was unsuccessful because {result.Status}"); } var tokProvider = new TokenFlow.Provider(); var auth_url = tokProvider.GetAuthorizeUrl(result.SessionToken); Response.Redirect(auth_url); } catch (OktaAuthenticationException o) { this.wizLoginFlow.MoveTo(this.stepPassword); ShowError(o.ErrorSummary); } catch (Exception e) { this.wizLoginFlow.MoveTo(this.stepPassword); var msg = e.InnerException != null ? e.InnerException.Message : e.Message; ShowError($"There was an error in your request {msg}"); } //TODO: DO SOMETHING }
protected void btnSubmit_Click(object sender, EventArgs e) { string newPassword = this.tbPassword.Text; string confirmPassword = this.tbConfirmPassword.Text; try { // validate OTT (recoveryToken) via /authn API // then call update user to set the password AuthResponse response = Factory.AuthnClient.ValidateToken(this.RecoveryToken); string userId = response.Embedded.User.Id; string username = response.Embedded.User.Profile.Login; Factory.UserClient.SetPassword(userId, newPassword); AuthResponse auth = Factory.AuthnClient.Authenticate(username, newPassword); string sessionToken = auth.SessionToken; TokenFlow.Provider tokProvider = new TokenFlow.Provider(); string auth_url = tokProvider.GetAuthorizeUrl(sessionToken); Response.Redirect(auth_url); } catch (Okta.Core.OktaException ox) { if (ox.ErrorCauses != null) { var errs = new List <string>(); errs.AddRange(ox.ErrorCauses.Select(x => x.ErrorSummary)); this.lblMessage.Text = $"Failed. Attempt to reset password failed because {string.Join(",", errs)}."; } else { this.lblMessage.Text = $"Failed. Attempt to reset password failed because {ox.Message}."; } } catch (Exception ex) { this.lblMessage.Text = $"Failed. Attempt to reset password failed because {ex.Message}."; } }