Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apple MusicKit Developer Token

Tags:

ios

token

I am following Apple's guide to musickit and I have been looking for a long time to resolve the following step:

Guide apple

I've already created the token.

Token

But I do not know what to do next where it says: "sign it with your MusicKit private key (see Create a MusicKit Private Key). Then encrypt the token using the Elliptic Curve Digital Signature Algorithm (ECDSA) with the P-256 curve and the SHA-256 hash algorithm. Specify the value ES256 in the algorithm header key (alg)".

I do not know how to encrypt ECDSA or where.

I do not know where to put the private keyword.

like image 226
Nuno Martins Avatar asked Jan 20 '18 20:01

Nuno Martins


2 Answers

If you're still curious about this then pelauimagineering's example which worked perfectly for me.

If you don't already have: Download pip, then two libraries: pyjwt & cryptography

On terminal do:

$ sudo easy_install pip
$ sudo pip install pyjwt
$ sudo pip install cryptography  
  • Clone pelauimagineering's repository and edit the music_token.py file replacing the secret variable with the .p8 key you downloaded.
  • Replace the keyId with the value you'll find at developer.apple.com under certificates > keys, and then click the key of the app you downloaded the .p8 file for and you'll see the key Id there.
  • Lastly, replace the teamId variable on the .py file with the 10 digit key found on your developer account at developer.apple.com/account and then click the membership tab and you'll see your 10 digit Id. Remember you need a developer token to do this which costs $99/year.
like image 140
Cole Maddux Avatar answered Oct 17 '22 22:10

Cole Maddux


Here's the sample code to generate the token for NodeJS:

const fs = require('fs');
const jwt = require('jsonwebtoken');

const privateKey = fs.readFileSync('AuthKey_1234.p8').toString(); // file downloaded when you created your key
const jwtToken = jwt.sign({}, privateKey, {
  algorithm: 'ES256',
  expiresIn: '180d',
  issuer: '1234V73RKG', // Your team ID
  header: {
    alg: 'ES256',
    kid: '1234VPQXH4' // ID from the Key with MusicKit permissions
  }
});


console.log("token:", jwtToken, "\n");

The JWT node module does all the hard work for you.

like image 1
Tom Roggero Avatar answered Oct 17 '22 21:10

Tom Roggero