Created
April 18, 2021 15:14
-
-
Save seresk/5831099f1a08b07561a8d1bb9edb5767 to your computer and use it in GitHub Desktop.
MusicKit JWT Token Generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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