public async Task <HeaderOnlyResponse> TwoFactorAuthenticate(TwoFactorVerificationMode mode, string code) { if (string.IsNullOrEmpty(Csrf)) { throw new Exception("CSRF not set; Identify user before authenticating two factor challenge"); } string method; switch (mode) { case TwoFactorVerificationMode.SMS: method = "authenticateSms"; break; case TwoFactorVerificationMode.EMail: method = "authenticateEmail"; break; default: throw new ArgumentOutOfRangeException(nameof(mode), mode, null); } var data = new TwoFactorAuthenticationRequest { Code = int.Parse(code), ChallengeReason = "DEVICE_AUTH", ChallengeMethod = "OP", Csrf = Csrf }; var httpMessage = await client.PostHttpEncodedData($"credential/{method}", data); return(await httpMessage.Content.ReadAsAsync <HeaderOnlyResponse>()); }
/// <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); }