Skip to content

kylepw/spotify-api-auth-examples

Repository files navigation

Spotify API Authorization Examples

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.

screenshots/search.png

For details on authorization flows, see Spotify's Authorization Guide

Requirements

  • Python 3.6+
  • Docker (only if running via docker)

Registration

  • Register your application with http://127.0.0.1:5000/callback as the redirect URI to obtain an application key and secret.

Setup

  • 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
    

Usage

Docker

  1. Run the following command. Set FLOW= to auth, client, or implicit:

    $ docker --rm --env-file .env -e FLOW=client -p 5000:5000 kylepw/spotify-api-auth-examples:latest
    
  2. Access http://127.0.0.1:5000 in a browser and click the login button.

From source

  1. Create a virtual environment (not required but highly recommended).

  2. Install required packages with pip, pipenv, or another package manager.

    $ pip install -r requirements.txt #-OR- 'pipenv install' if using pipenv
    
  1. 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)
     ...
    
  2. Access the address listed in a browser and click the login button.

License

MIT License

About

Examples of Spotify API's authentication flows using Python/Flask.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •