/// <summary> /// Set response value /// </summary> /// <param name="OTPMessage"></param> /// <param name="PWDMessage"></param> /// <param name="Passed"></param> /// <returns></returns> public static TwoFactorAuthenticationResponse SetResponseObjectValues(string OTPMessage, string PWDMessage, bool Passed) { TwoFactorAuthenticationResponse twoFactorAuthenticationResponse = new TwoFactorAuthenticationResponse(); twoFactorAuthenticationResponse.Passed = Passed; twoFactorAuthenticationResponse.ExceptionMessage = PWDMessage + " - " + OTPMessage; return(twoFactorAuthenticationResponse); }
/// <summary> /// Authenticates the credentials of the user /// </summary> /// <param name="twofactorObject"></param> /// <returns></returns> public TwoFactorAuthenticationResponse Authenticate(TwoFactorAuthenticationRequest TwoFactorAuthenticationRequest, string EventType) { TwoFactorAuthenticationResponse TwoFactorAuthenticationResponseObject = new TwoFactorAuthenticationResponse(); string response = string.Empty; try { if (TwoFactorAuthenticationRequest != null) { string parameter = string.Empty; string twoFactorAuthenticationServiceURL = string.Empty; Streamline.DataService.SharedTables objSharedTables = new Streamline.DataService.SharedTables(); if (Streamline.UserBusinessServices.SharedTables.DataSetSystemConfigurationKeys != null) { if (Streamline.UserBusinessServices.SharedTables.DataSetSystemConfigurationKeys.Tables.Count > 0) { twoFactorAuthenticationServiceURL = objSharedTables.GetSystemConfigurationKeys("TwoFactorAuthenticationServiceURL", Streamline.UserBusinessServices.SharedTables.DataSetSystemConfigurationKeys.Tables[0]); } } WebClient client = new WebClient(); client.Credentials = System.Net.CredentialCache.DefaultCredentials; client.Headers["Content-type"] = "application/json"; MemoryStream stream = new MemoryStream(); DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(TwoFactorAuthenticationRequest)); serializer.WriteObject(stream, TwoFactorAuthenticationRequest); byte[] data = client.UploadData(twoFactorAuthenticationServiceURL + "api/authenticate/" + TwoFactorAuthenticationRequest, "POST", stream.ToArray()); stream = new MemoryStream(data); serializer = new DataContractJsonSerializer(typeof(TwoFactorAuthenticationResponse)); TwoFactorAuthenticationResponseObject = (TwoFactorAuthenticationResponse)serializer.ReadObject(stream); SetUserInformation(TwoFactorAuthenticationResponseObject.Passed, EventType); } } catch { } finally { } return(TwoFactorAuthenticationResponseObject); }
public async Task <IActionResult> TwoFactorAuthentication() { var user = await _userManager.FindByIdAsync(User.FindFirst("id")?.Value); if (user == null) { return(BadRequest(new string[] { "Could not find user!" })); } var model = new TwoFactorAuthenticationResponse { HasAuthenticator = await _userManager.GetAuthenticatorKeyAsync(user) != null, Is2faEnabled = user.TwoFactorEnabled, RecoveryCodesLeft = await _userManager.CountRecoveryCodesAsync(user) }; return(Ok(model)); }