logging in with quick connect works now!
This commit is contained in:
parent
70c2372535
commit
6235a69e43
10 changed files with 131 additions and 64 deletions
Binary file not shown.
44
WindowsFormsApplication2/ConfigForm.Designer.cs
generated
44
WindowsFormsApplication2/ConfigForm.Designer.cs
generated
|
@ -47,8 +47,9 @@
|
|||
this.label6 = new System.Windows.Forms.Label();
|
||||
this.tabControl1 = new System.Windows.Forms.TabControl();
|
||||
this.tabPage2 = new System.Windows.Forms.TabPage();
|
||||
this.button2 = new System.Windows.Forms.Button();
|
||||
this.button1 = new System.Windows.Forms.Button();
|
||||
this.label9 = new System.Windows.Forms.Label();
|
||||
this.button4 = new System.Windows.Forms.Button();
|
||||
this.textBox4 = new System.Windows.Forms.TextBox();
|
||||
this.label5 = new System.Windows.Forms.Label();
|
||||
this.label4 = new System.Windows.Forms.Label();
|
||||
|
@ -221,8 +222,8 @@
|
|||
//
|
||||
// tabControl1
|
||||
//
|
||||
this.tabControl1.Controls.Add(this.tabPage2);
|
||||
this.tabControl1.Controls.Add(this.tabPage3);
|
||||
this.tabControl1.Controls.Add(this.tabPage2);
|
||||
this.tabControl1.Controls.Add(this.tabPage1);
|
||||
this.tabControl1.Location = new System.Drawing.Point(1, 0);
|
||||
this.tabControl1.Name = "tabControl1";
|
||||
|
@ -232,8 +233,9 @@
|
|||
//
|
||||
// tabPage2
|
||||
//
|
||||
this.tabPage2.Controls.Add(this.button2);
|
||||
this.tabPage2.Controls.Add(this.button1);
|
||||
this.tabPage2.Controls.Add(this.label9);
|
||||
this.tabPage2.Controls.Add(this.button4);
|
||||
this.tabPage2.Controls.Add(this.textBox4);
|
||||
this.tabPage2.Controls.Add(this.label5);
|
||||
this.tabPage2.Controls.Add(this.label4);
|
||||
|
@ -245,12 +247,32 @@
|
|||
this.tabPage2.Text = "Quick Connect";
|
||||
this.tabPage2.Click += new System.EventHandler(this.tabPage2_Click);
|
||||
//
|
||||
// button2
|
||||
//
|
||||
this.button2.Location = new System.Drawing.Point(71, 123);
|
||||
this.button2.Name = "button2";
|
||||
this.button2.Size = new System.Drawing.Size(134, 23);
|
||||
this.button2.TabIndex = 7;
|
||||
this.button2.Text = "Save URL and Close";
|
||||
this.button2.UseVisualStyleBackColor = true;
|
||||
this.button2.Click += new System.EventHandler(this.button2_Click);
|
||||
//
|
||||
// button1
|
||||
//
|
||||
this.button1.Location = new System.Drawing.Point(101, 65);
|
||||
this.button1.Name = "button1";
|
||||
this.button1.Size = new System.Drawing.Size(75, 23);
|
||||
this.button1.TabIndex = 6;
|
||||
this.button1.Text = "Confirm";
|
||||
this.button1.UseVisualStyleBackColor = true;
|
||||
this.button1.Click += new System.EventHandler(this.button1_Click);
|
||||
//
|
||||
// label9
|
||||
//
|
||||
this.label9.AutoEllipsis = true;
|
||||
this.label9.AutoSize = true;
|
||||
this.label9.FlatStyle = System.Windows.Forms.FlatStyle.System;
|
||||
this.label9.Location = new System.Drawing.Point(7, 74);
|
||||
this.label9.Location = new System.Drawing.Point(8, 70);
|
||||
this.label9.MaximumSize = new System.Drawing.Size(260, 0);
|
||||
this.label9.MinimumSize = new System.Drawing.Size(260, 0);
|
||||
this.label9.Name = "label9";
|
||||
|
@ -258,16 +280,6 @@
|
|||
this.label9.TabIndex = 5;
|
||||
this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// button4
|
||||
//
|
||||
this.button4.Location = new System.Drawing.Point(101, 116);
|
||||
this.button4.Name = "button4";
|
||||
this.button4.Size = new System.Drawing.Size(75, 23);
|
||||
this.button4.TabIndex = 4;
|
||||
this.button4.Text = "Submit";
|
||||
this.button4.UseVisualStyleBackColor = true;
|
||||
this.button4.Click += new System.EventHandler(this.button4_Click);
|
||||
//
|
||||
// textBox4
|
||||
//
|
||||
this.textBox4.Location = new System.Drawing.Point(8, 24);
|
||||
|
@ -318,6 +330,7 @@
|
|||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
|
||||
this.Text = "Server Config";
|
||||
this.TopMost = true;
|
||||
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.ConfigForm_FormClosing);
|
||||
this.Load += new System.EventHandler(this.ConfigForm_Load);
|
||||
this.tabPage1.ResumeLayout(false);
|
||||
this.tabPage1.PerformLayout();
|
||||
|
@ -348,7 +361,6 @@
|
|||
private System.Windows.Forms.Label label6;
|
||||
private System.Windows.Forms.TabControl tabControl1;
|
||||
private System.Windows.Forms.TabPage tabPage2;
|
||||
private System.Windows.Forms.Button button4;
|
||||
private System.Windows.Forms.TextBox textBox4;
|
||||
private System.Windows.Forms.Label label5;
|
||||
private System.Windows.Forms.Label label4;
|
||||
|
@ -356,5 +368,7 @@
|
|||
private System.Windows.Forms.ToolTip toolTip1;
|
||||
public System.Windows.Forms.TextBox textBox6;
|
||||
public System.Windows.Forms.MaskedTextBox maskedTextBox2;
|
||||
private System.Windows.Forms.Button button2;
|
||||
private System.Windows.Forms.Button button1;
|
||||
}
|
||||
}
|
|
@ -47,16 +47,15 @@ namespace JellyfinRPC
|
|||
this.Close();
|
||||
}
|
||||
|
||||
static string quickConnectLabel;
|
||||
private async void ConfigForm_Load(object sender, EventArgs e)
|
||||
private void ConfigForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
textBox1.Text = ConfigManager.GetEntry("ServerURL");
|
||||
textBox2.Text = ConfigManager.GetEntry("UserID");
|
||||
maskedTextBox1.Text = ConfigManager.GetEntry("APIKey");
|
||||
textBox4.Text = ConfigManager.GetEntry("ServerURL");
|
||||
textBox5.Text = ConfigManager.GetEntry("ServerURL");
|
||||
quickConnectLabel = await JellyfinAPI.SendQuickConnectRequest();
|
||||
label9.Text = quickConnectLabel;
|
||||
JellyfinAPI.formClosed = false;
|
||||
|
||||
}
|
||||
|
||||
private void label4_Click(object sender, EventArgs e)
|
||||
|
@ -78,10 +77,10 @@ namespace JellyfinRPC
|
|||
{
|
||||
|
||||
}
|
||||
|
||||
private void button4_Click(object sender, EventArgs e)
|
||||
{
|
||||
ConfigManager.SetEntry("ServerURL", textBox4.Text);
|
||||
|
||||
}
|
||||
|
||||
private void label6_Click(object sender, EventArgs e)
|
||||
|
@ -119,5 +118,22 @@ namespace JellyfinRPC
|
|||
{
|
||||
toolTip1.Show("Format like https://mydomain.local.", textBox1, textBox1.PointToClient(textBox1.Location).X + 30, textBox1.PointToClient(textBox1.Location).Y + 90, 2000);
|
||||
}
|
||||
|
||||
private async void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
button1.Hide();
|
||||
await JellyfinAPI.AuthWithQuickConnect();
|
||||
}
|
||||
|
||||
private void button2_Click(object sender, EventArgs e)
|
||||
{
|
||||
ConfigManager.SetEntry("ServerURL", textBox4.Text);
|
||||
Close();
|
||||
}
|
||||
|
||||
private void ConfigForm_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
JellyfinAPI.formClosed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ using System.Reflection;
|
|||
using System.Security.Cryptography;
|
||||
using Newtonsoft.Json;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
namespace JellyfinRPC
|
||||
{
|
||||
|
@ -179,47 +180,83 @@ namespace JellyfinRPC
|
|||
}
|
||||
return "album_cover";
|
||||
}
|
||||
public static async Task<string> SendQuickConnectRequest()
|
||||
public static string quickConnectToken;
|
||||
static bool authSuccess;
|
||||
public static bool formClosed;
|
||||
|
||||
public static async Task AuthWithQuickConnect()
|
||||
{
|
||||
using var httpClient = new HttpClient();
|
||||
httpClient.DefaultRequestHeaders.Add("Authorization", $"MediaBrowser Client=\"JellyfinRPC\", Device=\"{Environment.OSVersion}\", DeviceId=\"{ConfigManager.GetEntry("DeviceID")}\", Version=\"{AssemblyVersion}\"");
|
||||
httpClient.DefaultRequestHeaders.Add("Authorization", $"MediaBrowser Client=\"JellyfinRPC {AssemblyVersion}, \", Device=\"{System.Net.Dns.GetHostName()}\", DeviceId=\"{ConfigManager.GetEntry("DeviceID")}\", Version=\"running on {Environment.OSVersion}\"");
|
||||
if (ConfigManager.GetEntry("ServerURL") != "")
|
||||
{
|
||||
var response = await httpClient.GetAsync($"{ConfigManager.GetEntry("ServerURL")}/QuickConnect/Initiate");
|
||||
if (response.StatusCode is (System.Net.HttpStatusCode)401)
|
||||
var quickConnectInitResponse = await httpClient.GetAsync($"{ConfigManager.GetEntry("ServerURL")}/QuickConnect/Initiate");
|
||||
authSuccess = false;
|
||||
if (quickConnectInitResponse.StatusCode is (System.Net.HttpStatusCode)401)
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show("This server does not have Quick Connect enabled.", "Quick Connect Unavailable.", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error, System.Windows.Forms.MessageBoxDefaultButton.Button1);
|
||||
return "Error: Server does not have Quick Connect Enabled.";
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
response.EnsureSuccessStatusCode();
|
||||
var jsonResponse = await response.Content.ReadAsStringAsync();
|
||||
quickConnectInitResponse.EnsureSuccessStatusCode();
|
||||
var jsonResponse = await quickConnectInitResponse.Content.ReadAsStringAsync();
|
||||
var jsonObject = JObject.Parse(jsonResponse);
|
||||
|
||||
if (!jsonObject.HasValues)
|
||||
{
|
||||
return "Error: Server did not respond.";
|
||||
}
|
||||
else
|
||||
{
|
||||
string quickConnectCode = jsonObject.Value<string>("Code");
|
||||
string quickConnectToken = jsonObject.Value<string>("Secret");
|
||||
return quickConnectCode;
|
||||
if (jsonObject.Value<string>("Secret") != null && jsonObject.Value<string>("Secret") != "")
|
||||
{
|
||||
quickConnectToken = jsonObject.Value<string>("Secret");
|
||||
}
|
||||
else
|
||||
{
|
||||
quickConnectToken = null;
|
||||
}
|
||||
|
||||
(System.Windows.Forms.Application.OpenForms["ConfigForm"] as ConfigForm).label9.Text = quickConnectCode;
|
||||
while (authSuccess == 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;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return $"{ex.Message.Trim()}";
|
||||
#if DEBUG
|
||||
System.Windows.Forms.MessageBox.Show(ex.ToString());
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return "Error: No Server URL Set.";
|
||||
System.Windows.Forms.MessageBox.Show("No Server URL Set", "Quick Connect Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -246,16 +283,16 @@ namespace JellyfinRPC
|
|||
var loginRequest = new Login() { username = username, pw = password };
|
||||
var loginJson = JsonConvert.SerializeObject(loginRequest);
|
||||
|
||||
HttpResponseMessage response = await httpClient.PostAsync($"{ConfigManager.GetEntry("ServerURL")}/Users/AuthenticateByName", new StringContent(loginJson, Encoding.UTF8, "application/json"));
|
||||
if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
|
||||
HttpResponseMessage loginWithUsernameandPassResponse = await httpClient.PostAsync($"{ConfigManager.GetEntry("ServerURL")}/Users/AuthenticateByName", new StringContent(loginJson, Encoding.UTF8, "application/json"));
|
||||
if (loginWithUsernameandPassResponse.StatusCode == System.Net.HttpStatusCode.Unauthorized)
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show("The Username or Password is incorrect.", "Authentication Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error, System.Windows.Forms.MessageBoxDefaultButton.Button1);
|
||||
}
|
||||
else
|
||||
{
|
||||
response.EnsureSuccessStatusCode();
|
||||
loginWithUsernameandPassResponse.EnsureSuccessStatusCode();
|
||||
|
||||
var jsonResponse = await response.Content.ReadAsStringAsync();
|
||||
var jsonResponse = await loginWithUsernameandPassResponse.Content.ReadAsStringAsync();
|
||||
|
||||
var jsonShit = JObject.Parse(jsonResponse);
|
||||
|
||||
|
@ -269,6 +306,32 @@ namespace JellyfinRPC
|
|||
}
|
||||
}
|
||||
}
|
||||
public static async Task<string> CheckQuickConnectStatus()
|
||||
{
|
||||
using var httpClient = new HttpClient();
|
||||
if (quickConnectToken != null && quickConnectToken != "")
|
||||
{
|
||||
|
||||
TaskEx.Delay(1000);
|
||||
string secret = quickConnectToken.Replace('"', ' ').Trim();
|
||||
HttpResponseMessage QuickConnectStatusResponse = await httpClient.GetAsync($"{ConfigManager.GetEntry("ServerURL")}/QuickConnect/Connect?Secret={quickConnectToken}");
|
||||
QuickConnectStatusResponse.EnsureSuccessStatusCode();
|
||||
var responseAsString = await QuickConnectStatusResponse.Content.ReadAsStringAsync();
|
||||
var responseJson = JObject.Parse(responseAsString);
|
||||
if (responseJson.ContainsKey("AccessToken"))
|
||||
{
|
||||
return responseJson.Value<string>("AccessToken");
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return "this isn't gonna work";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Login
|
||||
|
@ -278,30 +341,4 @@ namespace JellyfinRPC
|
|||
public string pw { get; set; }
|
||||
#pragma warning restore IDE1006 // Naming Styles
|
||||
}
|
||||
public class QuickConnect
|
||||
{
|
||||
[JsonProperty("Authenticated")]
|
||||
public bool Authenticated { get; set; }
|
||||
|
||||
[JsonProperty("Secret")]
|
||||
public string Secret { get; set; }
|
||||
|
||||
[JsonProperty("Code")]
|
||||
public string Code { get; set; }
|
||||
|
||||
[JsonProperty("DeviceId")]
|
||||
public string DeviceId { get; set; }
|
||||
|
||||
[JsonProperty("DeviceName")]
|
||||
public string DeviceName { get; set; }
|
||||
|
||||
[JsonProperty("AppName")]
|
||||
public string AppName { get; set; }
|
||||
|
||||
[JsonProperty("AppVersion")]
|
||||
public string AppVersion { get; set; }
|
||||
|
||||
[JsonProperty("DateAdded")]
|
||||
public DateTime DateAdded { 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