diff --git a/AyaNovaQBI/tfa.cs b/AyaNovaQBI/tfa.cs index 8eb20a1..ab89554 100644 --- a/AyaNovaQBI/tfa.cs +++ b/AyaNovaQBI/tfa.cs @@ -12,7 +12,7 @@ namespace AyaNovaQBI { public partial class tfa : Form { - public string TFACode { get; set; } + public string TFAPin { get; set; } public tfa() { InitializeComponent(); @@ -24,18 +24,15 @@ namespace AyaNovaQBI } - private async void btnVerifyCode_click(object sender, EventArgs e) + private void btnVerifyCode_click(object sender, EventArgs e) { - - var res = await util.AuthenticateTFAAsync(ed); - if (!res) + + TFAPin = edTFACode.Text; + if (string.IsNullOrWhiteSpace(TFAPin)) { - MessageBox.Show("Login failed"); - btnLogin.Enabled = btnTest.Enabled = true; - this.DialogResult = DialogResult.Cancel; + MessageBox.Show("TFA Code is required to log in"); return; } - this.DialogResult = DialogResult.OK; this.Close(); } diff --git a/AyaNovaQBI/util.cs b/AyaNovaQBI/util.cs index 4eb296a..67a8a31 100644 --- a/AyaNovaQBI/util.cs +++ b/AyaNovaQBI/util.cs @@ -37,7 +37,7 @@ namespace AyaNovaQBI } client = new HttpClient(); client.Timeout = TimeSpan.FromSeconds(HTTPCLIENT_TIMEOUT_SECONDS); - + } /// @@ -93,29 +93,39 @@ namespace AyaNovaQBI if (ex.InnerException != null) InnerErr = ex.InnerException.Message; return false; - // throw new Exception("POST error, route: " + route + "\r\nError:" + Err + "\r\nInner error:" + InnerErr + "\r\nStack:" + ex.StackTrace + "\r\nPOSTED OBJECT:\r\n" + postJson); + // throw new Exception("POST error, route: " + route + "\r\nError:" + Err + "\r\nInner error:" + InnerErr + "\r\nStack:" + ex.StackTrace + "\r\nPOSTED OBJECT:\r\n" + postJson); } //ApiResponse a = await PostAsync("auth", creds.ToString()); if (response.IsSuccessStatusCode) { - - - - var a= new ApiResponse() { HttpResponse = response, ObjectResponse = Parse(await response.Content.ReadAsStringAsync()) }; + var a = new ApiResponse() { HttpResponse = response, ObjectResponse = Parse(await response.Content.ReadAsStringAsync()) }; bool tfa = a.ObjectResponse["data"]["tfa"].Value(); if (tfa == true) { - //get 2fa code and send it in - tfa t = new tfa(); - if(t.ShowDialog()==System.Windows.Forms.DialogResult.Cancel) return false; + //Get temp token from response + var tempToken = a.ObjectResponse["data"]["tt"].Value(); + string tfaPin = null; + bool keepTrying = true; + //get 2fa code and send it in + do + { + tfa t = new tfa(); + if (t.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) return false; + tfaPin = t.TFAPin; + + + + } while (keepTrying); } - - JWT = a.ObjectResponse["data"]["token"].Value(); - return true; + else + { + JWT = a.ObjectResponse["data"]["token"].Value(); + return true; + } } return false; @@ -123,7 +133,6 @@ namespace AyaNovaQBI - public async static Task GetAsync(string route) { Exception FirstException = null; @@ -149,7 +158,7 @@ namespace AyaNovaQBI private async static Task TryGetAsync(string route) { var requestMessage = new HttpRequestMessage(HttpMethod.Get, ApiBaseUrl + route); - + if (!string.IsNullOrWhiteSpace(JWT)) requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", JWT); @@ -229,7 +238,7 @@ namespace AyaNovaQBI { var requestMessage = new HttpRequestMessage(HttpMethod.Post, ApiBaseUrl + route); - + if (!string.IsNullOrWhiteSpace(JWT)) requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", JWT); @@ -336,7 +345,7 @@ namespace AyaNovaQBI public async static Task TryPutAsync(string route, string putJson = null) { var requestMessage = new HttpRequestMessage(HttpMethod.Put, ApiBaseUrl + route); - + if (!string.IsNullOrWhiteSpace(JWT)) requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", JWT);