quick connect auth *actually* works this time, but for whatever reason the entire thing freezes if there's a token set
This commit is contained in:
parent
c3b202af23
commit
c9e2e7fb5f
8 changed files with 35 additions and 30 deletions
Binary file not shown.
|
@ -181,8 +181,8 @@ namespace JellyfinRPC
|
|||
return "album_cover";
|
||||
}
|
||||
public static string quickConnectToken;
|
||||
static bool authSuccess;
|
||||
public static bool formClosed;
|
||||
public static bool authSuccess;
|
||||
|
||||
public static async Task AuthWithQuickConnect()
|
||||
{
|
||||
|
@ -204,6 +204,7 @@ namespace JellyfinRPC
|
|||
var jsonResponse = await quickConnectInitResponse.Content.ReadAsStringAsync();
|
||||
var jsonObject = JObject.Parse(jsonResponse);
|
||||
|
||||
|
||||
if (!jsonObject.HasValues)
|
||||
{
|
||||
}
|
||||
|
@ -218,29 +219,10 @@ namespace JellyfinRPC
|
|||
{
|
||||
quickConnectToken = null;
|
||||
}
|
||||
|
||||
(System.Windows.Forms.Application.OpenForms["ConfigForm"] as ConfigForm).label9.Text = quickConnectCode;
|
||||
while (authSuccess == false)
|
||||
while (authSuccess == false && formClosed == false)
|
||||
{
|
||||
var getThings = await CheckQuickConnectStatus();
|
||||
if (formClosed == true)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if (getThings == null)
|
||||
{
|
||||
await CheckQuickConnectStatus();
|
||||
}
|
||||
else if (getThings == "this isn't gonna work")
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show("Quick Connect doesn't seem to be working. Check your Internet connection and try again later.", "Quick Connect Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
authSuccess = true;
|
||||
|
||||
}
|
||||
await CheckQuickConnectStatus();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -306,7 +288,7 @@ namespace JellyfinRPC
|
|||
}
|
||||
}
|
||||
}
|
||||
public static async Task<string> CheckQuickConnectStatus()
|
||||
public static async Task CheckQuickConnectStatus()
|
||||
{
|
||||
using var httpClient = new HttpClient();
|
||||
if (quickConnectToken != null && quickConnectToken != "")
|
||||
|
@ -318,19 +300,38 @@ namespace JellyfinRPC
|
|||
QuickConnectStatusResponse.EnsureSuccessStatusCode();
|
||||
var responseAsString = await QuickConnectStatusResponse.Content.ReadAsStringAsync();
|
||||
var responseJson = JObject.Parse(responseAsString);
|
||||
if (responseJson.ContainsKey("AccessToken"))
|
||||
if (responseJson.Value<bool>("Authenticated") == true)
|
||||
{
|
||||
return responseJson.Value<string>("AccessToken");
|
||||
var quickConnectLoginSecret = new QuickConnect() { Secret = quickConnectToken };
|
||||
var quickConnectLoginJson = JsonConvert.SerializeObject(quickConnectLoginSecret);
|
||||
HttpResponseMessage quickConnectLoginResponse = await httpClient.PostAsync($"{ConfigManager.GetEntry("ServerURL")}/Users/AuthenticateWithQuickConnect", new StringContent(quickConnectLoginJson, Encoding.UTF8, "application/json"));
|
||||
quickConnectLoginResponse.EnsureSuccessStatusCode();
|
||||
var quickConnectLoginResponseAsString = await quickConnectLoginResponse.Content.ReadAsStringAsync();
|
||||
var quickConnectLoginResponseJson = JObject.Parse(quickConnectLoginResponseAsString);
|
||||
if (quickConnectLoginResponseJson.HasValues)
|
||||
{
|
||||
if (quickConnectLoginResponseJson.Value<string>("AccessToken") != null && quickConnectLoginResponseJson.Value<string>("AccessToken") != "")
|
||||
{
|
||||
ConfigManager.SetEntry("JellyfinToken", quickConnectLoginResponseJson.Value<string>("AccessToken"));
|
||||
authSuccess = true;
|
||||
(System.Windows.Forms.Application.OpenForms["ConfigForm"] as ConfigForm).label9.Text = "Authentication Successful.";
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("The server did not return an access token, this shouldn't happen.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show("The server didn't respond for authentication.", "Authentication Error.", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
authSuccess = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return "this isn't gonna work";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -341,4 +342,8 @@ namespace JellyfinRPC
|
|||
public string pw { get; set; }
|
||||
#pragma warning restore IDE1006 // Naming Styles
|
||||
}
|
||||
public class QuickConnect
|
||||
{
|
||||
public string Secret { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue