Spotify.NET/SpotifyAPI.Web.Examples/Example.ASP/SpotifyClientBuilder.cs
2020-05-22 12:23:25 +02:00

27 lines
789 B
C#

using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Http;
using SpotifyAPI.Web;
namespace Example.ASP
{
public class SpotifyClientBuilder
{
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly SpotifyClientConfig _spotifyClientConfig;
public SpotifyClientBuilder(IHttpContextAccessor httpContextAccessor, SpotifyClientConfig spotifyClientConfig)
{
_httpContextAccessor = httpContextAccessor;
_spotifyClientConfig = spotifyClientConfig;
}
public async Task<SpotifyClient> BuildClient()
{
var token = await _httpContextAccessor.HttpContext.GetTokenAsync("Spotify", "access_token");
return new SpotifyClient(_spotifyClientConfig.WithToken(token));
}
}
}