diff --git a/SpotifyAPI.Web.Auth/AuthorizationCodeAuth.cs b/SpotifyAPI.Web.Auth/AuthorizationCodeAuth.cs index 4ca46dc1..e7e24df9 100644 --- a/SpotifyAPI.Web.Auth/AuthorizationCodeAuth.cs +++ b/SpotifyAPI.Web.Auth/AuthorizationCodeAuth.cs @@ -55,16 +55,9 @@ namespace SpotifyAPI.Web.Auth new KeyValuePair("refresh_token", refreshToken) }; - HttpClientHandler handler = ProxyConfig.CreateClientHandler(ProxyConfig); - HttpClient client = new HttpClient(handler); - client.DefaultRequestHeaders.Add("Authorization", GetAuthHeader()); - HttpContent content = new FormUrlEncodedContent(args); - - HttpResponseMessage resp = await client.PostAsync("https://accounts.spotify.com/api/token", content); - string msg = await resp.Content.ReadAsStringAsync(); - - return JsonConvert.DeserializeObject(msg); + return await GetToken(args); } + public async Task ExchangeCode(string code) { List> args = new List> @@ -74,7 +67,13 @@ namespace SpotifyAPI.Web.Auth new KeyValuePair("redirect_uri", RedirectUri) }; - HttpClient client = new HttpClient(); + return await GetToken(args); + } + + private async Task GetToken(IEnumerable> args) + { + HttpClientHandler handler = ProxyConfig.CreateClientHandler(ProxyConfig); + HttpClient client = new HttpClient(handler); client.DefaultRequestHeaders.Add("Authorization", GetAuthHeader()); HttpContent content = new FormUrlEncodedContent(args);