Bart Simons

Bart Simons


Thoughts, stories and ideas.

Bart Simons
Author

Share


Tags


.net .net core Apache C# CentOS LAMP NET Framework Pretty URLs Windows Server WireGuard WireGuard.io access log add analysis android api at the same time authentication authorization automate automation azure azurerm backup bash basics batch bootstrap build capture cheat sheet chromium chroot class cli click to close code snippet command line commands compile compiling compression containers control controller controlling convert cpu usage create credentials csv csvparser curl data dd deployment desktop detect devices disable diskpart dism distributed diy docker dom changes dotnet core drivers ease of access encryption example export file transfer files fix folders generalize getting started ghost ghost.org gui guide gunicorn gzip html html tables icewarp igd imagex import inotify install installation interactive ios iphone itunes java javascript jquery json kiosk kotlin linux live load data loading screen lock screen loopback audio lxc lxd lxml macos manage manually message messages minio mirrored mod_rewrite monitor monitoring mutationobserver mysql nexmo nginx no oobe node node.js nodejs not installing notification notifications object storage on desktop one command openssl owncloud parallels parallels tools parse perfect philips hue play port forwarding portainer.io powershell processing ps-spotify python quick raspberry pi record rip ripping rsync rtmp save save data sbapplication scraping script scripting scriptingbridge scripts security send server service sharedpreferences sms songs sonos spotify spotify api spotlight ssh stack streaming streamlink studio sudo swarm swift sync sysprep system audio systemd tables terminal tracking tutorial twilio ubiquiti ubuntu ubuntu 18.04 ui code unifi unlock unsplash source upnp uptime usb tethering wallpapers wasapi website websites webview windows windows 10 without itunes without oobe workaround xaml

.NET Core and the Spotify API - Getting authenticated

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:

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.

Spotify app dashboard

Spotify app

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.

SpotifyController.cs

Now you can run the application from your command prompt or terminal:

dotnet run

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:

Spotify API 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.

Bart Simons
Author

Bart Simons

View Comments