2019-11-19 09:37:42 +00:00
|
|
|
|
using System.Diagnostics;
|
2019-11-12 14:02:30 +00:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.AspNetCore.Authentication;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using SpotifyAPI.Web.Examples.ASP.Models;
|
|
|
|
|
|
|
|
|
|
namespace SpotifyAPI.Web.Examples.ASP.Controllers
|
|
|
|
|
{
|
2019-11-19 12:23:34 +00:00
|
|
|
|
[Authorize(AuthenticationSchemes = "Spotify")]
|
2019-11-12 14:02:30 +00:00
|
|
|
|
public class HomeController : Controller
|
|
|
|
|
{
|
2019-11-19 09:37:42 +00:00
|
|
|
|
public async Task<IActionResult> Index()
|
2019-11-12 14:02:30 +00:00
|
|
|
|
{
|
2019-11-19 09:37:42 +00:00
|
|
|
|
var accessToken = await HttpContext.GetTokenAsync("Spotify", "access_token");
|
|
|
|
|
SpotifyWebAPI api = new SpotifyWebAPI
|
2019-11-12 14:02:30 +00:00
|
|
|
|
{
|
|
|
|
|
AccessToken = accessToken,
|
2019-11-19 09:37:42 +00:00
|
|
|
|
TokenType = "Bearer"
|
2019-11-12 14:02:30 +00:00
|
|
|
|
};
|
2019-11-19 09:37:42 +00:00
|
|
|
|
|
|
|
|
|
var savedTracks = await api.GetSavedTracksAsync(50);
|
|
|
|
|
|
|
|
|
|
return View(new IndexModel { SavedTracks = savedTracks });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
|
|
|
public IActionResult Error()
|
|
|
|
|
{
|
|
|
|
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
2019-11-12 14:02:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-11-19 09:37:42 +00:00
|
|
|
|
}
|