public async Task <string> RequestAccessToken() { FormUrlEncodedContent tokenRequestContent = new FormUrlEncodedContent(new Dictionary <string, string>() { { "grant_type", "client_credentials" } }); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", SpotifyHelpers.GetEncodedAuth(clientId, clientSecret)); HttpResponseMessage responseMessage = await httpClient.PostAsync(SpotifyConstants.RequestAccessTokenUrl, tokenRequestContent); authenticationType = SpotifyConstants.AuthenticationType.ClientCredentials; return(await ProcessAuthorizationResponse(responseMessage)); }
public async Task <string> RefreshAccessToken() { if (authenticationType == SpotifyConstants.AuthenticationType.None) { throw new Exception("Client not authenticated yet."); } else if (authenticationType == SpotifyConstants.AuthenticationType.AuthorizationCode) { FormUrlEncodedContent refreshRequestContent = new FormUrlEncodedContent(new Dictionary <string, string>() { { "grant_type", "refresh_token" }, { "refresh_token", RefreshToken } }); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", SpotifyHelpers.GetEncodedAuth(clientId, clientSecret)); HttpResponseMessage responseMessage = await httpClient.PostAsync(SpotifyConstants.RequestAccessTokenUrl, refreshRequestContent); return(await ProcessAuthorizationResponse(responseMessage)); } else if (authenticationType == SpotifyConstants.AuthenticationType.ClientCredentials) { return(await RequestAccessToken()); } else { throw new NotImplementedException("New authorization type not implemented"); } }