Spotify User Authorization Flow (in Go)
See https://developer.spotify.com/documentation/general/guides/authorization-guide/ for details on User Authorization
This was written for use with the Spotify iOS-SDK but should work with minor or no changes with other setups.
-
Set environment variables
SPOTIFY_CLIENT_ID
,SPOTIFY_CLIENT_SECRET
andSPOTIFY_AUTH_REDIRECT_URI
. Client ID, Client Secret are from your Spotify Developer account and redirect URI is specific to your app (see source code for notes). -
Copy/symlink your https key and cert files into the same directory (DER or PEM format seems to work)
-
That's it. Just run it (only argument is the listening port), or put in a systemd unit to have it run detached from a terminal or use the
Dockerfile
editing it for your needs to build a docker image to run.
Access tokens can be generated by either swapping with an access code or using a refresh token.
This should run much faster than any other implementation I've seen and is easier to setup (if you're familiar with Go and Linux). It uses the https://github.com/julienschmidt/httprouter Go package, which I've really found to be better than the standard Go package, but it's easy enough to remove that dependecy and use the stock router or another one.
See the source code for additional information.