diff --git a/.vs/WindowsFormsApplication2/v16/.suo b/.vs/WindowsFormsApplication2/v16/.suo index 17a5f93..ccafb1c 100644 Binary files a/.vs/WindowsFormsApplication2/v16/.suo and b/.vs/WindowsFormsApplication2/v16/.suo differ diff --git a/WindowsFormsApplication2/JellyfinAPI.cs b/WindowsFormsApplication2/JellyfinAPI.cs index 80b70b9..cf640ae 100644 --- a/WindowsFormsApplication2/JellyfinAPI.cs +++ b/WindowsFormsApplication2/JellyfinAPI.cs @@ -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() { @@ -203,6 +203,7 @@ namespace JellyfinRPC quickConnectInitResponse.EnsureSuccessStatusCode(); 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 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("Authenticated") == true) { - return responseJson.Value("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("AccessToken") != null && quickConnectLoginResponseJson.Value("AccessToken") != "") + { + ConfigManager.SetEntry("JellyfinToken", quickConnectLoginResponseJson.Value("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; } + } } diff --git a/WindowsFormsApplication2/bin/Debug/Jellyfin Rich Presence.exe b/WindowsFormsApplication2/bin/Debug/Jellyfin Rich Presence.exe index 19db3d0..2b87036 100644 Binary files a/WindowsFormsApplication2/bin/Debug/Jellyfin Rich Presence.exe and b/WindowsFormsApplication2/bin/Debug/Jellyfin Rich Presence.exe differ diff --git a/WindowsFormsApplication2/bin/Debug/Jellyfin Rich Presence.pdb b/WindowsFormsApplication2/bin/Debug/Jellyfin Rich Presence.pdb index 0dc6693..819874c 100644 Binary files a/WindowsFormsApplication2/bin/Debug/Jellyfin Rich Presence.pdb and b/WindowsFormsApplication2/bin/Debug/Jellyfin Rich Presence.pdb differ diff --git a/WindowsFormsApplication2/obj/x86/Debug/Jellyfin Rich Presence.exe b/WindowsFormsApplication2/obj/x86/Debug/Jellyfin Rich Presence.exe index 19db3d0..2b87036 100644 Binary files a/WindowsFormsApplication2/obj/x86/Debug/Jellyfin Rich Presence.exe and b/WindowsFormsApplication2/obj/x86/Debug/Jellyfin Rich Presence.exe differ diff --git a/WindowsFormsApplication2/obj/x86/Debug/Jellyfin Rich Presence.pdb b/WindowsFormsApplication2/obj/x86/Debug/Jellyfin Rich Presence.pdb index 0dc6693..819874c 100644 Binary files a/WindowsFormsApplication2/obj/x86/Debug/Jellyfin Rich Presence.pdb and b/WindowsFormsApplication2/obj/x86/Debug/Jellyfin Rich Presence.pdb differ diff --git a/WindowsFormsApplication2/obj/x86/Debug/JellyfinRPCGUI.csproj.AssemblyReference.cache b/WindowsFormsApplication2/obj/x86/Debug/JellyfinRPCGUI.csproj.AssemblyReference.cache index 9c7abdf..f5e894a 100644 Binary files a/WindowsFormsApplication2/obj/x86/Debug/JellyfinRPCGUI.csproj.AssemblyReference.cache and b/WindowsFormsApplication2/obj/x86/Debug/JellyfinRPCGUI.csproj.AssemblyReference.cache differ diff --git a/WindowsFormsApplication2/obj/x86/Debug/JellyfinRPCGUI.csproj.GenerateResource.Cache b/WindowsFormsApplication2/obj/x86/Debug/JellyfinRPCGUI.csproj.GenerateResource.Cache index d957a35..5a191dc 100644 Binary files a/WindowsFormsApplication2/obj/x86/Debug/JellyfinRPCGUI.csproj.GenerateResource.Cache and b/WindowsFormsApplication2/obj/x86/Debug/JellyfinRPCGUI.csproj.GenerateResource.Cache differ