Welcome back on my blog! I've recently had some busy weeks and now that I am back, I am really exited to demonstrate one of my projects that I have been working on in the past to you. Spotify is a daily service that I and millions of other people use to listen to music. When I found out that they had an API available, I started to study their documentation to see what the possibilities are. After one week of thinking I came up with two ideas to work out into a working product:
- A .NET Core webapp to handle the authentication flow of the Spotify Web API.
- A PowerShell module to provide logical wrapper functions to most of the API endpoints.
Creating a Spotify app
Creating is fairly easy to be honest, you don't need a developer account - the only thing you need is your existing Spotify account. When you are planning to use the Spotify Web API, you are bound to this idea of authentication. Spotify itself has a blog article available that covers the authentication and authorization setup and flow step-by-step.
You can create a Spotify app on this page.
As you can see in the last screenshot, we do now have a client ID and a client secret. These two tokens are meant to be integrated into your server-side authentication flow. Spotify has made its own example repository available over here, but since this example covers a lot of other purposes too I decided to make my own version in dotnet core - solely for the purpose of authenticating users for your Spotify app.
Installation and configuration is very simple: clone the repo, put the client ID and client secret into the SpotifyController.cs file.
Now you can run the application from your command prompt or terminal:
Please note that the readme file in my repo contains more detailed information regarding the configuration and installation. If you geet stuck at some point, you should check the README.md.
Open up your web browser and navigate to http://localhost:5000. This should open up a page with a single button. Click on that button and you will be redirected to Spotify, asking you if this app should be able to access your account. Once you have approved your account, you will be redirected back to localhost with the following response:
And this is how you get an access and refresh token for your Spotify app. In the next article I'll demonstrate how my PowerShell module for Spotify works and to showcase some of the functionality provided by the Spotify Web API.