Create Rest API to download Apple wallet (.pkpass) file using Spring, Java

Mumtaz
3 min readJan 19, 2020

An Apple’s wallet pass is nothing but a bundle, a zipped folder containing :

  1. Resources like logo, background image, translations
  2. A pass.json file which defines the pass, contains some metadata information and indicates how each of the images have to be displayed in the pass.
  3. A manifest.json file which describes files inside the pass and has SHA1 checksums of each of the files.

But before we can get started you need to:

  1. Create an Apple developer account, if you do not already have one.
  2. Get a .p12 certificate file along with the password to open this file. This will contain Pass type identifier which is needed for digitally signing your Pass for use with Wallet. Type identifier is a String value using reverse DNS style — for example, pass.com.example.id-card .Please note that only admins of Developer account will be able to create this certificate. To create this certificate follow these steps or refer this blog post.
  • In Certificates, Identifiers & Profiles, select Identifiers.
  • Under Identifiers, select Pass Type IDs.
  • Select the pass type identifier, then click Edit.
  • If there is a certificate listed under Production Certificates, click the Download button next to it.
  • If there are no certificates listed, click the Create Certificate button, then follow the instructions to create a pass signing certificate.

3. Get Apple’s WWDR certificate from here.

So let’s get started.

In this post we will be designing a generic pass and create the bundle (zipped folder with all resources, json files) programatically. A generic pass has the following sections:

For list of all supported pass types refer Apple documentation here.

Let’s say we have a User with following fields which will be displayed on the pass:

  • firstName
  • lastName
  • uuid — displayed as QR code
  • uniqueID
  • imageURL — the profile photo of the user

We will use jpasskit Java library. Source code of the library can be found here. I am using gradle to build my code, so to include the library in your project add following to your build.gradle file:

compile group: ‘de.brendamour’, name: ‘jpasskit’, version: ‘0.1.1’compile(‘com.google.guava:guava:23.2-jre’)

We do not want to save the Pass in the file system. As and when the user requests we create a byte array representing the zipped bundle of a .pkpass file and write it to the response. The library exposes equivalent methods if you want to physically save the Pass on the system.

Let’s create a Service class:

Create a Controller class:

It is very important to set the Content-Type to application/vnd.apple.pkpass for browsers to understand that it is wallet pass file.

So when the browser sends GET requestto https://.../passkit the pass gets downloaded with filenameuser_id_card_userFirstName_userLastName .

And it looks like:

pass as displayed in Mac

--

--