Apple now provides a tool for turning your Team ID, MapKit key, and MapKit Key ID into a JWT. https://maps.developer.apple.com/token-maker
In order to use MapKit JS or MusicKit JS you need to generate a JWT to authenticate your requests. Unfortuneatly this isn't straight forward and Apple's documentation isn't super helpful with showing you how to generate a JWT.
MapKit JS requires authorization via JSON Web Tokens (JWT) for initialization and some API calls. You obtain a key used to create the token when you complete the setup in your Apple Developer account.
This simple Python program should help you generate a JWT you can use for development.
JSON Web Tokens are a method for representing claims securely between two parties. For more information check out jwt.io
You can create the Map ID in the developer portal (developer.apple.com) in the Certificates, Identifiers & Profiles
tab.
2. Your Key ID
Next you will generate a new key. You will need the ID of this key to generate the JWT.
Download the private key. You will only be able to download this once. Save it in a private, safe place. You can open this key file with a text editor and copy the entire contents of the file for inserting into main.py
.
You will need this ID to generate your JWT. You can get this under the Membership
tab on the home page of the developer portal.
You probably just want an easy way to generate your JWT so you can move on with development. 😉 Fine, here is how you can use this program.
Note: These directions are for macOS
- Clone this repository -
$ git clone git@github.com:addisonwebb/Apple-JWT-Generator.git
- Verify you have Python installed -
$ python --version
Output will likely bePython 2.7.10
- Install pip -
$ sudo easy_install pip
- Install virtualenv -
$ sudo -H pip install virtualenv
- Change to the root directory of the project
- Setup a virtual environment -
$ virtualenv env
- Begin using virtual environment -
$ source env/bin/activate
- Install pyjwt -
$ pip install pyjwt
- Install cryptography -
$ pip install cryptography
- Update
main.py
with the values for your Team ID, Key ID, and private key. Save the file. - Back in terminal run the program -
$ python main.py
You should see output that looks like the following:
fyFhbEciOiJFUzI1NiIsInR5cC16IkpXVCIsImtpZCI6IkNTTFo2QjdNOFoifQ.eyJpc3MiOiJGSjRVQk02Uko3IiwiaWF0IjoxNTMwMDcwMtkyLjMyNQA4OSwiZXhwIjoxNTMwMDcxOTkyLjMyNDA4OX0.uveH2BifavlkJp8KLUPCHC0Eh9C6igaUdA6jIawW0r1wsOo44mNSq53e_bH8ZoB2JcNSqXqYvKVYEREi6S02gq
🎉 This is the JWT you use to authenticate requests via the MapKit JS and MusicKit JS.