Git Product home page Git Product logo

setlist-sherlock-apple-music-token-server's Introduction

Setlist Sherlock - Apple Music Token Server

This AWS Lambda function issues a "Developer Token" (basically a JWT) signed with an Apple MusicKit private key, set to expire 6 months from the request time. These developer tokens are needed to allow Android Apple Music users (they do exist!) to authenticate. By using a Lambda function instead of storing the developer private key locally, you don't risk someone extracting your key from the compiled app. This is a good developer practice.

Develop

Node 20+ is recommended. Install dependencies with:

$ yarn

Environment Variables

Copy the .env.example to .env and fill in the values.

The APPLE_TEAM_ID is the Team ID under "membership details" section.

To get your MUSICKIT_PRIVATE_KEY, head to Certificates, Identifiers & Profiles -> Keys, then create a "Media Services" key. You'll need to click "configure" and add a media ID that you can create by going to Identifiers and selecting "Media IDs". Click "download" for the key to get the p8 key file, and open it in a text editor, removing the new lines.

After completing this step, you can also obtain your MUSICKIT_PRIVATE_KEY_ID. Click on the key you created and use the "Key ID".

Test

Deploy the function locally using yarn test, this requires Docker to be set up.

Deploy

To deploy this Lambda function, you need to install the AWS CLI. Run the below script, replacing <aws-account-id> with your AWS's numeric ID. Optionally provide a <region-code>, otherwise us-east-1 is used.

This command will build the Docker image used for testing and deploy it to a ECR repository, and create the Lambda function if it doesn't exist already.

This script may not work on Powershell on Windows. Use a Windows Subsystem for Linux installation.

$ yarn deploy <aws-account-id> <region-code>

If you'd prefer to deploy with CloudFormation, you can use the AWS SAM CLI.

Known issues

  • The command that updates the Lambda's environment variables sometimes fails with a "ResourceConflictException". Run it manually if you need to add/update environment variables: aws lambda update-function-configuration --region <your-aws-region> --function-name <your-DEPLOY_LAMBDA_NAME-value> --environment "Variables={EnvVar1=Value1,EnvVar2=Value2}"
  • The first time you create the function, the command fails with a "InvalidParameterValueException". The Lambda execution role does in fact work, just run the deploy again.
  • If you're using the "function URL" feature, it's not set up properly by the script (because AWS's CLI is crappy) - you'll need to go into the Lambda function in the console, to the "configuration" tab then "function URL" in the side navigation, click Edit then Save. It'll add a policy that allows public access. Alternatively you can set up IAM authentication for your endpoint.

setlist-sherlock-apple-music-token-server's People

Contributors

dylmye avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.