This is an instance of a 'Spotify auth server' which acts as an interface between a client and the Spotify oauth API.
With go
installed, run
go get -u github.com/conradludgate/terraform-provider-spotify/spotify_auth_proxy
First, you need a Spotify client ID and secret. Visit https://developer.spotify.com/dashboard/ to create an application.
If you plan to run this proxy locally, set the redirect URI of the application to http://localhost:27228/spotify_callback
.
If you're running it remotely, substitute an appropiate base url (eg https://spotify.example.com/spotify_callback
)
You will also need to register the callback URI with Spotify for your application. Visit https://developer.spotify.com/dashboard/, click on your application, find and click the "Edit Settings" button, and paste the spotify_callback
URI above into "Redirect URIs". Scroll down and click "Save".
To start the server, make sure the environment variables SPOTIFY_CLIENT_ID
and SPOTIFY_CLIENT_SECRET
are set from the values on the Spotify dashboard.
If running remotely, also configure your base url
export SPOTIFY_PROXY_BASE_URI=https://spotify.example.com
Finally, run
spotify_auth_proxy
It should output the following:
APIKey: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Auth URL: ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
Take note of these values.
Now, open a browser and navigate to the Auth URL. It should redirect you to Spotify to log in. After you log in, the auth server will redirect you back to the page where it should confirm that you've authorized correctly.
The API Key is how you will retrieve the access token. The server will handle the token expiration and refreshes for you.
The API Key is random on each invocation, you can specify the SPOTIFY_PROXY_API_KEY
environment variable to keep it consistent
Alternatively, you can use the Docker to run the Spotify auth proxy.
First, create a file named .env
and populate it with your SPOTIFY_CLIENT_ID
and SPOTIFY_CLIENT_SECRET
values. Your file should look similar to the following.
SPOTIFY_CLIENT_ID=
SPOTIFY_CLIENT_SECRET=
Then, run the following command to start the auth proxy.
$ docker run --rm -it -p 27228:27228 --env-file ./.env ghcr.io/conradludgate/spotify-auth-proxy
APIKey: OK7b1j...
Token: aoIvJT...
Auth: http://localhost:27228/authorize?token=aoIvJT...