This script requires three elements:
- Team Id — available on the Developer console by clicking “Membership” in the left column
- Private Key — downloadable as a .p8 file after following these instructions to create your MusicKit identifier and private key
- Key Id — also available by following the instructions above or accessible anytime in “Certificates, Identifiers & Profiles” on the Developer console. It should also be part of the file name of your private key. 👌🏻
Once you have these three elements ready. Download or compose the following code as
musickit-token-encoder.js and make sure it’s in the same directly as your .p8 file. Make sure the filename of privateKey matches that of your .p8 file. Then simply adjust the teamId and keyId to reflect your elements above. The script will then spit out an API token you can use to power your MusicKit JS app.
I’ve noticed a cookie issue when arriving to a previously authenticated experience and have reported it on the Apple Developer forums. Try using an incognito window if you face the same issue.