This commit is contained in:
2022-06-20 22:27:33 +00:00
parent 0e7d1de1ed
commit 7ced9e377c
2 changed files with 31 additions and 25 deletions

View File

@@ -12,7 +12,7 @@ namespace AyaNovaQBI
{ {
public partial class tfa : Form public partial class tfa : Form
{ {
public string TFACode { get; set; } public string TFAPin { get; set; }
public tfa() public tfa()
{ {
InitializeComponent(); 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); TFAPin = edTFACode.Text;
if (!res) if (string.IsNullOrWhiteSpace(TFAPin))
{ {
MessageBox.Show("Login failed"); MessageBox.Show("TFA Code is required to log in");
btnLogin.Enabled = btnTest.Enabled = true;
this.DialogResult = DialogResult.Cancel;
return; return;
} }
this.DialogResult = DialogResult.OK; this.DialogResult = DialogResult.OK;
this.Close(); this.Close();
} }

View File

@@ -37,7 +37,7 @@ namespace AyaNovaQBI
} }
client = new HttpClient(); client = new HttpClient();
client.Timeout = TimeSpan.FromSeconds(HTTPCLIENT_TIMEOUT_SECONDS); client.Timeout = TimeSpan.FromSeconds(HTTPCLIENT_TIMEOUT_SECONDS);
} }
/// <summary> /// <summary>
@@ -93,29 +93,39 @@ namespace AyaNovaQBI
if (ex.InnerException != null) if (ex.InnerException != null)
InnerErr = ex.InnerException.Message; InnerErr = ex.InnerException.Message;
return false; 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()); //ApiResponse a = await PostAsync("auth", creds.ToString());
if (response.IsSuccessStatusCode) 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<bool>(); bool tfa = a.ObjectResponse["data"]["tfa"].Value<bool>();
if (tfa == true) if (tfa == true)
{ {
//get 2fa code and send it in //Get temp token from response
tfa t = new tfa();
if(t.ShowDialog()==System.Windows.Forms.DialogResult.Cancel) return false;
var tempToken = a.ObjectResponse["data"]["tt"].Value<string>();
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);
} }
else
JWT = a.ObjectResponse["data"]["token"].Value<string>(); {
return true; JWT = a.ObjectResponse["data"]["token"].Value<string>();
return true;
}
} }
return false; return false;
@@ -123,7 +133,6 @@ namespace AyaNovaQBI
public async static Task<ApiResponse> GetAsync(string route) public async static Task<ApiResponse> GetAsync(string route)
{ {
Exception FirstException = null; Exception FirstException = null;
@@ -149,7 +158,7 @@ namespace AyaNovaQBI
private async static Task<ApiResponse> TryGetAsync(string route) private async static Task<ApiResponse> TryGetAsync(string route)
{ {
var requestMessage = new HttpRequestMessage(HttpMethod.Get, ApiBaseUrl + route); var requestMessage = new HttpRequestMessage(HttpMethod.Get, ApiBaseUrl + route);
if (!string.IsNullOrWhiteSpace(JWT)) if (!string.IsNullOrWhiteSpace(JWT))
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", JWT); requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", JWT);
@@ -229,7 +238,7 @@ namespace AyaNovaQBI
{ {
var requestMessage = new HttpRequestMessage(HttpMethod.Post, ApiBaseUrl + route); var requestMessage = new HttpRequestMessage(HttpMethod.Post, ApiBaseUrl + route);
if (!string.IsNullOrWhiteSpace(JWT)) if (!string.IsNullOrWhiteSpace(JWT))
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", JWT); requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", JWT);
@@ -336,7 +345,7 @@ namespace AyaNovaQBI
public async static Task<ApiResponse> TryPutAsync(string route, string putJson = null) public async static Task<ApiResponse> TryPutAsync(string route, string putJson = null)
{ {
var requestMessage = new HttpRequestMessage(HttpMethod.Put, ApiBaseUrl + route); var requestMessage = new HttpRequestMessage(HttpMethod.Put, ApiBaseUrl + route);
if (!string.IsNullOrWhiteSpace(JWT)) if (!string.IsNullOrWhiteSpace(JWT))
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", JWT); requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", JWT);