Jonas Dellinger

HomeProjectsBlogResume

SpotifyAPI-NET

🔉 A Client for the Spotify Web API, written in C#/.NET

Links

Introduction

This is my first rather larger open-source project, which started January 2014. In the beginning it was rather limited and only allowed to make authenticated calls to the spotify api and return typed responses. Now, the project evolved including various additional features for the spotify api:

  • Supports .NET Standard 2, which includes all major desktop and mobile platforms

    • .NET Framework
    • UWP
    • .NET Core
    • Xamarin.Forms
  • Included HTTPClient, but feel free to bring your own!
  • Logging supported
  • Retry Handlers supported
  • Proxy support
  • Pagination support
  • All OAuth2 Authentications supported for use in ASP .NET and CLI apps
  • Modular structure, easy unit testing
  • Typed responses and requests to over 74 endpoints. Complete and always up to date.

OAuth Integration

One rather larger feature is the straight forward usage of the OAuth2 spotify provider. With just several lines one can access and retrive an access token ready to be used.

// In this example: PKCE Auth Flow
var (verifier, challenge) = PKCEUtil.GenerateCodes();

var _server = new EmbedIOAuthServer(new Uri("http://localhost:5000/callback"), 5000);
_server.AuthorizationCodeReceived += async (sender, response) =>
{
  await _server.Stop();

  PKCETokenResponse token = await new OAuthClient().RequestToken(
    new PKCETokenRequest(clientId, response.Code, _server.BaseUri, verifier)
  );

  // token can now be used to access the spotify API
};
await _server.Start();

var request = new LoginRequest(_server.BaseUri, clientId, LoginRequest.ResponseType.Code)
{
  CodeChallenge = challenge,
  CodeChallengeMethod = "S256",
  Scope = new List<string> { UserReadEmail, UserReadPrivate, PlaylistReadPrivate, PlaylistReadCollaborative }
};
BrowserUtil.Open(request.ToUri());

Technologies/Techniques

  • C# 8
  • OAuth2
  • JSON
  • CI/CD via AppVeyor
  • Documentation via Docusaurus (CD as well)
  • Unit Testing