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 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();
}

View File

@@ -37,7 +37,7 @@ namespace AyaNovaQBI
}
client = new HttpClient();
client.Timeout = TimeSpan.FromSeconds(HTTPCLIENT_TIMEOUT_SECONDS);
}
/// <summary>
@@ -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<bool>();
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>();
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<string>();
return true;
else
{
JWT = a.ObjectResponse["data"]["token"].Value<string>();
return true;
}
}
return false;
@@ -123,7 +133,6 @@ namespace AyaNovaQBI
public async static Task<ApiResponse> GetAsync(string route)
{
Exception FirstException = null;
@@ -149,7 +158,7 @@ namespace AyaNovaQBI
private async static Task<ApiResponse> 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<ApiResponse> 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);