public async Task <IActionResult> Callback(string code, string state, string error) { if (error != null) { return(RedirectToRoute("/login/unauthorized")); } CallbackResponse cr; using (var client = new HttpClient()) { var values = new Dictionary <string, string> { { "client_id", client_id }, { "client_secret", client_secret }, { "grant_type", "authorization_code" }, { "code", code }, { "redirect_uri", redirect_uri } }; var content = new FormUrlEncodedContent(values); var response = await client.PostAsync("https://accounts.spotify.com/api/token", content); var responseString = await response.Content.ReadAsStringAsync(); cr = JsonConvert.DeserializeObject <CallbackResponse>(responseString); } string responseJson = await SpotifyApi.ApiManager.Auth_Get("https://api.spotify.com/v1/me", cr.access_token); Console.WriteLine(responseJson); //save user on sign-up User CurrentUser = UserAdapter.ParseUserJson(responseJson, 1); //generate and save session information CurrentUser = UserAdapter.GetUserBySpotifyUserId(CurrentUser.UserId); Session s = SessionAdapter.GenerateSession(CurrentUser.Id); //Set the cookies value Response.Cookies.Append("Trackify-Auth", s.Code); Response.Cookies.Append("Trackify-UId", s.UserId.ToString()); return(RedirectToAction("Index", "Home")); }