This project contains examples of Spotify API's three authorization flows using Python/Flask:
- Authorization Code
- Client Credentials
- Implicit Grant
The authorization code and implicit grant flow examples show the authorizing user's profile, token information, and a button that refreshes the access token.
The client credentials flow example includes a search function that lists artist information from Spotify.
For details on authorization flows, see Spotify's Authorization Guide
- Python 3.6+
- Docker (only if running via docker)
- Register your application with
http://127.0.0.1:5000/callback
as the redirect URI to obtain an application key and secret.
Clone the repository and step inside.
$ git clone https://github.com/kylepw/spotify-api-auth-examples.git $ cd spotify-api-auth-examples
Set the required environment variables:
$ cp env-template .env $ vim .env #Replace `XXX`'s with your values in vim or another editor. $ set -a; source .env; set +a
Run the following command. Set
FLOW=
toauth
,client
, orimplicit
:$ docker --rm --env-file .env -e FLOW=client -p 5000:5000 kylepw/spotify-api-auth-examples:latest
Access http://127.0.0.1:5000 in a browser and click the login button.
Create a virtual environment (not required but highly recommended).
Install required packages with pip, pipenv, or another package manager.
$ pip install -r requirements.txt #-OR- 'pipenv install' if using pipenv
Step into one of the three example folders and startup the server.
$ cd authorization_code && flask run * Serving Flask app "app.py" (lazy loading) * Environment: development * Debug mode: on * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) ...
Access the address listed in a browser and click the login button.