Authenticating to Apple’s App Store Connect API from Node.js using JWT

Félix Paradis
1 min readFeb 27, 2019

I had to connect to Apple’s new App Store Connect API at work and found exactly 0 tutorial and/or code example on how to achieve this from Node.js, which I use. (I did find a good one for Ruby, though, if that’s your thing.)

It’s not very complex, but if you’ve never used JSON Web Tokens before, you might fall in a dumb gotcha like I did. Also, once you do get to generate tokens, if something is wrong with them you will get “401 NOT_AUTHORIZED” as your only clue. So, here I am, saving you some time.

I’m using the jsonwebtoken npm package, but you could use an alternative.

Without further ado, the snippet you need to get going quickly.

Of course, you’ll want to use something else than curl once you authenticate successfully. You’ll probably want to avoid hosting your secret key (the .p8 file) on your server nor commit it as well, but those are considerations for when you can use the API!

Hope this was helpful, cheers !🍻

--

--

Félix Paradis

Web Developer writing about the web, mostly. Find my other stuff over at www.felixparadis.com