RecapTimeSquad / spotify-auth-proxy-railwayapp

An @railwayapp starter for the Spotify Auth Proxy server as part of https://learn.hashicorp.com/tutorials/terraform/spotify-playlist.

Home Page:https://github.com/conradludgate/terraform-provider-spotify

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Spotify Auth Proxy Railway Starter

⚠️ 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.

Project Information

Usage

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
}

Setting up your own auth proxy

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.

As an Railway starter

  1. To get things started, press the Deploy on Railway button below1 and fill out SPOTIFY_CLIENT_ID and SPOTIFY_CLIENT_SECRET with your OAuth application's values. If you're managing playlists though Terraform on regular basis, we recommend setting SPOTIFY_PROXY_API_KEY variable to avoid hassles. 2

    Deploy on Railway

    Here's an example of how do we configure it from that screen:

    Demo of configurations, with the proxy API key being censored partially

  2. 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 Edited in MS Paint with shapes and text for proper doc/guidance.

    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.

    Setting the proxy base URI in Railway

  3. 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 with spotify_callback after the trailing slash, press Add and save.3

    Setting the proxy base URI in Railway

  4. 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.

    Latest deployment logs

    Scroll down and hit Agree to authorize your auth proxy to create, edit and manage playlists.

    OAuth prompt

    The auth proxy should response with Authorization successful after the redirection. OAuth prompt

    Now keep your API key secret and continue the tutorial process. Happy Terraforming!

Using the repositry template generation in GitHub

  1. 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.

  2. 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

    OAuth prompt

  3. Continue to step 2 in As an Railway starter section and happy Terraforming!

Footnotes

  1. 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

  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.

  3. Remember that changing your *.up.railway.app subdomain might break the OAuth callback and token exchange processes, so don't forget to update your SPOTIFY_PROXY_BASE_URI and allowed callback URLs.

  4. The screenshot in this step uses SPOTIFY_PROXY_API_TOKEN instead of SPOTIFY_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.

About

An @railwayapp starter for the Spotify Auth Proxy server as part of https://learn.hashicorp.com/tutorials/terraform/spotify-playlist.

https://github.com/conradludgate/terraform-provider-spotify

License:Mozilla Public License 2.0


Languages

Language:Shell 73.1%Language:Dockerfile 26.9%