diff --git a/ChaosBot/WebServer/App/DiscordController.cs b/ChaosBot/WebServer/App/DiscordController.cs index 26f2133..2d7dc84 100644 --- a/ChaosBot/WebServer/App/DiscordController.cs +++ b/ChaosBot/WebServer/App/DiscordController.cs @@ -1,7 +1,9 @@ using System.Collections.Generic; +using System.Linq; using System.Net.Http; using System.Net.Http.Headers; using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Newtonsoft.Json; @@ -45,16 +47,17 @@ namespace ChaosBot.WebServer.App } [HttpGet("user")] - public IActionResult GetUser(string access_token) + public IActionResult GetUser() { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", access_token); + if (!Request.Cookies.TryGetValue("access_token", out string accessToken)) + accessToken = null; HttpResponseMessage response; using (HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, "https://discord.com/api/v7/users/@me")) { requestMessage.Headers.Authorization = - new AuthenticationHeaderValue("Bearer", access_token); + new AuthenticationHeaderValue("Bearer", accessToken); response = client.SendAsync(requestMessage).GetAwaiter().GetResult(); } string responseString = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); @@ -64,16 +67,17 @@ namespace ChaosBot.WebServer.App } [HttpGet("guilds")] - public IActionResult GetGuilds(string access_token) + public IActionResult GetGuilds() { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", access_token); + if (!Request.Cookies.TryGetValue("access_token", out string accessToken)) + accessToken = null; HttpResponseMessage response; using (HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, "https://discord.com/api/v7/users/@me/guilds")) { requestMessage.Headers.Authorization = - new AuthenticationHeaderValue("Bearer", access_token); + new AuthenticationHeaderValue("Bearer", accessToken); response = client.SendAsync(requestMessage).GetAwaiter().GetResult(); } string responseString = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); diff --git a/ChaosBot/wwwroot b/ChaosBot/wwwroot index d5f6bef..205122b 160000 --- a/ChaosBot/wwwroot +++ b/ChaosBot/wwwroot @@ -1 +1 @@ -Subproject commit d5f6beff41569ca8b8cf6e38fa48a03a32824623 +Subproject commit 205122b26ade4c897300fe23682fe6b47609c6be