mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2024-12-27 16:26:27 +00:00
27 lines
789 B
C#
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));
|
|
}
|
|
}
|
|
}
|