This Flask app helps streamline the tedious process of generating a Spotify access token through the Implicit Grant Flow.
To get the app running:
- Install the required dependencies:
pip3 install -r requirements.txt
- Configure your .env file with the following variables (a .env.example file can be found in the root of the repo):
SECRET_KEY
: This is required to use FlaskForms and can be generated with Python 3'sos
orsecrets
module.- In a Python shell, simply copy the output of either of the following commands into your .env file:
# option 1 - generate key with os module import os os.urandom(32) # option 2 - generate key with secrets module import secrets secrets.token_hex(16)
- In a Python shell, simply copy the output of either of the following commands into your .env file:
CLIENT_ID
: This is taken from an existing application in your Spotify developer dashboard (you will need to create one if you don't already have one).RESPONSE_TYPE='token'
: The required parameter for obtaining authorization through the Implicit Grant Flow.REDIRECT_URI='http://localhost:5000/auth/callback/'
: This is the URL/route that is designed to work with this application. It must be white-listed in your application.- To do this, visit: https://developer.spotify.com/dashboard/applications. Select your app. Go to EDIT SETTINGS > Redirect URIs, add in the URL and click SAVE.
- (Optional) You can remove or configure the default scope by adding to or removing from the
scope
variable in theauth
view function.- You can read about the various authorization scopes on: https://developer.spotify.com/documentation/general/guides/scopes/.
- Once everything is configured to your liking, run the application using:
flask run
From there, you should be able to access the application via browser at http://localhost:5000/. Once you submit the form, it will redirect you to a login page asking to authorize the app to view your account. Once you've accepted, it will redirect you to the callback URL where you can copy the access token right off of the HTML page.