⚠️ You only connect one Spotiy account per server. You may need separate environments pointing to same branch but different base URIs. If you need multi-user auth proxy, check out https://github.com/conradludgate/oauth2-proxy.
An @railwayapp starter for the Spotify Auth Proxy server as part of https://learn.hashicorp.com/tutorials/terraform/spotify-playlist, through we deploy the proxy.
- Authors/Maintainers: Andrei Jiroh Halili ([email protected])
- License: MPL 2.0
terraform {
required_providers {
spotify = {
version = "~> 0.1.5"
source = "conradludgate/spotify"
}
}
}
provider "spotify" {
auth_server = "https://your-app-here.up.railway.app" # this is fine since URLs are public as long as don't leak the API keys or the auth links
api_key = var.spotify_api_key
}
Before you proceed: Complete the prerequsite part by creating an OAuth client in Spotify for Developers dashboard page with these instructions. Leave the redirect URIs unfilled for now.
-
To get things started, press the Deploy on Railway button below1 and fill out
SPOTIFY_CLIENT_ID
andSPOTIFY_CLIENT_SECRET
with your OAuth application's values. If you're managing playlists though Terraform on regular basis, we recommend settingSPOTIFY_PROXY_API_KEY
variable to avoid hassles. 2Here's an example of how do we configure it from that screen:
-
After the starter is successfully deployed, you'll be redirected to the project dashboard. Navigate to Deployments -> Domains and copy the production deployment URL. by right-clicking and selecting copy URL
The next step will be use that URL you copied as
SPOTIFY_PROXY_BASE_URI
, since we ran our proxy in the cloud, not locally, minus the trailing slash. -
Go back to Spotify for Developers dashboard of your OAuth client, hit Edit Settings and add your Railway deployment URL (hint: your
SPOTIFY_PROXY_BASE_URI
), suffixing withspotify_callback
after the trailing slash, press Add and save.3 -
For the moment of the truth, go back to your Railway project dashboard, select Deployments -> latest deploy. Click the Auth URL to start the OAuth flow.
Scroll down and hit Agree to authorize your auth proxy to create, edit and manage playlists.
The auth proxy should response with
Authorization successful
after the redirection.Now keep your API key secret and continue the tutorial process. Happy Terraforming!
-
Use this link or press Use this template button in the main repository. Give it an fresh repository slug of your choice r maybe try GitHub-generated ones and choose privacy setting. Hit Create repository from template. Refresh at will.
-
Sign up for Railway using your GitHub account1, then start here using this link. Select the repository you just generated and fill up some variables.4
-
Continue to step 2 in
As an Railway starter
section and happy Terraforming!
Footnotes
-
Affliate link notice: By signing up to Railway using the link above for new users, you'll receive $5 credit to use at your dispoal. We'll only receive $5 on our side if you upgraded to the Developer plan and paid your first bill, irrespective of the bill amunt. ↩ ↩2
-
Since the API Key is random on each invocation by default, this might break your Terraforming session on every deploy, so we recommend doing that. ↩
-
Remember that changing your
*.up.railway.app
subdomain might break the OAuth callback and token exchange processes, so don't forget to update yourSPOTIFY_PROXY_BASE_URI
and allowed callback URLs. ↩ -
The screenshot in this step uses
SPOTIFY_PROXY_API_TOKEN
instead ofSPOTIFY_PROXY_API_KEY
as variable name for the custom proxy API key. We added some patches by creating an startup script here to handle this. ↩