This is a simple backend project providing authorization and authentication to Spotify's Web API. Built using Express.js to deploy on AWS Lambda using the Serverless framework. You will need to have your own app registered with Spotify and your own AWS account setup your Lambda functions.
You will need:
- Register your app - need a client id, secret and redirect URI
- Node.js - version
6.5.0or later - Severless - run
npm install -g serverlessto install - AWS CLI -
pip install awscli --upgrade --usermore info here Install AWS CLI - AWS account - Create and configure your AWS Profiles
If you are rolling your own backend make sure to have your app registered with Spotify. They have a great Quick Start Guide documenting how to create your first app with Spotify. You will need your App's Client ID, Client Secret, and Callback URI
Now that your App is registered and AWS account is configured you can update the serverless.yml with your details.
- Add your AWS profile configured above
provider:
name: aws
runtime: nodejs6.10
stage: prod
region: us-east-1
profile: add-your-profile-
Configure your environment variables. We are keeping our keys private using AWS SSM and calling them through the process environments. You need to define a
spotify_secretand aspotify_id-
Create stored parameters using the CLI
aws ssm put-parameter --name spotify_secret --type String --value F6tcdxJ2cxhNf1NeSifoa8E4g6N0fZTR
-
Define them in serverless.yml
environment: SPOTIFY_ID: ${ssm:spotify_id} SPOTIFY_SECRET: ${ssm:spotify_secret}
-
add them to the project
-
const client_secret = process.env.SPOTIFY_SECRET; // Your secret
-
Deploy your function
$ sls deploy
... snip ...
Service Information
service: vivify-backend-application
stage: prod
region: us-east-1
stack: vivify-backend-application-prod
api keys:
None
endpoints:
ANY - https://bl4r0gjjv5.execute-api.us-east-1.amazonaws.com/prod
ANY - https://bl4r0gjjv5.execute-api.us-east-1.amazonaws.com/prod/{proxy+}
functions:
app: my-express-application-dev-appYou can find your client id and secret in the Spotify Developer Dashboard
More info on the Spotify Web API Console
This project uses the Authorization Code Flow.
-
Request user authorization
curl https://your-aws-url.execute-api.us-east-1.amazonaws.com/prod/login
-
Request refresh and access tokens
-
curl https://your-aws-url.execute-api.us-east-1.amazonaws.com/prod/getTokens/{code} -
Request a refreshed access token
curl https://your-aws-url.execute-api.us-east-1.amazonaws.com/prod/refresh_token/{token}
- AWS Lambda
- Express.js
- Severless Framework