Skip to content

Instantly share code, notes, and snippets.

@seresk
Created April 18, 2021 15:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seresk/5831099f1a08b07561a8d1bb9edb5767 to your computer and use it in GitHub Desktop.
Save seresk/5831099f1a08b07561a8d1bb9edb5767 to your computer and use it in GitHub Desktop.
MusicKit JWT Token Generator
"use strict";
const fs = require("fs");
const jwt = require("jsonwebtoken");
const request = require("request");
const privateKey = fs.readFileSync("AuthKey.p8").toString(); //your MusicKit private key
const jwtToken = jwt.sign({}, privateKey, {
algorithm: "ES256",
expiresIn: "180d",
issuer: "**********", //your 10-character Team ID, obtained from your developer account
header: {
alg: "ES256",
kid: "**********" //your MusicKit Key ID
}
});
console.log("Your developer token:", jwtToken, "\n");
// sample service call
request.get(
{
url: "https://api.music.apple.com/v1/catalog/us/songs/203709340",
auth: {
bearer: jwtToken
},
json: true
},
(err, httpResponse, body) => {
if (err) {
console.log('error:')
console.error(err);
} else {
console.log('success:')
console.log(body);
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment