Skip to content

Instantly share code, notes, and snippets.

@zachomedia
Created June 23, 2018 22:06
Show Gist options
  • Save zachomedia/a6e3f6f68091c6aa333da50d7b44a330 to your computer and use it in GitHub Desktop.
Save zachomedia/a6e3f6f68091c6aa333da50d7b44a330 to your computer and use it in GitHub Desktop.
// Based on https://codegists.com/snippet/javascript/indexjs_aljs_javascript
// (found from https://forums.developer.apple.com/thread/103790)
// npm install jsonwebtoken
"use strict";
const fs = require("fs");
const jwt = require("jsonwebtoken");
const privateKey = fs.readFileSync("AuthKey.p8").toString(); //your MusicKit private key
const jwtToken = jwt.sign({}, privateKey, {
algorithm: "ES256",
expiresIn: "180d",
issuer: "TEAM_ID", //your 10-character Team ID, obtained from your developer account
header: {
alg: "ES256",
kid: "MUSICKIT_KEY_ID" //your MusicKit Key ID
}
});
console.log(jwtToken);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment