How to Create a Spotify App and Generate Auth Keys and Tokens for API Consumption

Mihir Samant
3 min readJun 2, 2024

--

In this blog post, I will guide you through the process of creating a Spotify app and generating the necessary authentication keys and tokens to consume the Spotify Web API. Whether you’re looking to build a music discovery app, manage playlists, or access user data, understanding these steps is crucial.

  1. Create a Spotify Account (just basic account you dont need premium)
  2. Visit this link https://developer.spotify.com/documentation/web-api
  3. Click on Dashboard and Click on Create App

4. Fill out the information as below. DO NOT forget to put Redirect URIs as http://localhost:8888/callback. ( we need this to get Auth Token from server)

5. Go to Dashboard > select your App (name) > Settings > Client ID / Client Secrets

6. You need to add those credentils (ClientID and Client Secrets) in Your Airflow UI > Admin > Connections and Save

Generating Auth Key

An authentication key in Spotify is crucial for accessing the Spotify Web API securely. It involves using OAuth 2.0 to grant permission for an application to access user data. The process starts with obtaining an authorization code, which is then exchanged for an access token. This token is used to authenticate API requests on behalf of the user. Proper management and storage of these keys are essential to protect user information and maintain secure communication with Spotify’s services.

Once you done with saving client ID and Secrets we need to run your Flask Server on your local machine.
This will keep on accepting a callbacks from your Spotify App requests

from flask import Flask, request

app = Flask(__name__)

@app.route('/callback')
def callback():
auth_code = request.args.get('code')
return f'Authorization code: {auth_code}'

if __name__ == '__main__':
app.run(port=8888)

Once your Flask Server is up and running your need to test it with below link please modify the link as per your ClientID.
Remember you have to keep the Flask Server running while generating Auth Key
You will see below as an output when you run above code

ignore my spotify typo :P

Then Copy past with your clientID on your browser and hit enter and you will see a long string this string is nothing but your Auth Key.

https://accounts.spotify.com/authorize?client_id=YOUR_CLIENT_ID&response_type=code&redirect_uri=http://localhost:8888/callback&scope=user-read-recently-played

Add this Auth key in a Variable in Airflow for Future use.

Jump Back to Airflow + Spotify using below link

--

--