From 9d9bed4cb20c74b3b05e42e38bfd5a2971549152 Mon Sep 17 00:00:00 2001 From: Battlefield Duck Date: Tue, 23 Jan 2024 05:50:08 +0800 Subject: [PATCH] Update EOS.cs --- OpenGSQ/Protocols/EOS.cs | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/OpenGSQ/Protocols/EOS.cs b/OpenGSQ/Protocols/EOS.cs index 6578452..33a7eaa 100644 --- a/OpenGSQ/Protocols/EOS.cs +++ b/OpenGSQ/Protocols/EOS.cs @@ -52,13 +52,18 @@ public static async Task GetAccessTokenAsync(string clientId, string cli { string url = $"{_apiUrl}/auth/v1/oauth/token"; - var queryString = System.Web.HttpUtility.ParseQueryString(string.Empty); - queryString.Add("grant_type", grantType); - queryString.Add("external_auth_type", externalAuthType); - queryString.Add("external_auth_token", externalAuthToken); - queryString.Add("nonce", "opengsq"); - queryString.Add("deployment_id", deploymentId); - queryString.Add("display_name", "User"); + var values = new Dictionary + { + { "grant_type", grantType }, + { "external_auth_type", externalAuthType }, + { "external_auth_token", externalAuthToken }, + { "nonce", "opengsq" }, + { "deployment_id", deploymentId }, + { "display_name", "User" }, + }; + + var content = new FormUrlEncodedContent(values); + var queryString = await content.ReadAsStringAsync(); string authInfo = $"{clientId}:{clientSecret}"; authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo)); @@ -72,7 +77,7 @@ public static async Task GetAccessTokenAsync(string clientId, string cli } }) { - HttpResponseMessage response = await client.PostAsync(url, new StringContent(queryString.ToString(), Encoding.UTF8, "application/x-www-form-urlencoded")); + HttpResponseMessage response = await client.PostAsync(url, new StringContent(queryString, Encoding.UTF8, "application/x-www-form-urlencoded")); response.EnsureSuccessStatusCode(); var data = await response.Content.ReadFromJsonAsync>(); @@ -96,8 +101,13 @@ public static async Task GetExternalAuthTokenAsync(string clientId, stri { string url = $"{_apiUrl}/auth/v1/accounts/deviceid"; - var queryString = System.Web.HttpUtility.ParseQueryString(string.Empty); - queryString.Add("deviceModel", "PC"); + var values = new Dictionary + { + { "deviceModel", "PC" }, + }; + + var content = new FormUrlEncodedContent(values); + var queryString = await content.ReadAsStringAsync(); string authInfo = $"{clientId}:{clientSecret}"; authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo)); @@ -111,7 +121,7 @@ public static async Task GetExternalAuthTokenAsync(string clientId, stri } }) { - HttpResponseMessage response = await client.PostAsync(url, new StringContent(queryString.ToString(), Encoding.UTF8, "application/x-www-form-urlencoded")); + HttpResponseMessage response = await client.PostAsync(url, new StringContent(queryString, Encoding.UTF8, "application/x-www-form-urlencoded")); response.EnsureSuccessStatusCode(); var data = await response.Content.ReadFromJsonAsync>();