Skip to content

Instantly share code, notes, and snippets.

@dlazares
Created November 17, 2022 23:56
Show Gist options
  • Save dlazares/c68fec4b0fa05a631a5452e8a050cd57 to your computer and use it in GitHub Desktop.
Save dlazares/c68fec4b0fa05a631a5452e8a050cd57 to your computer and use it in GitHub Desktop.
Apple oauth token generator
const jwt = require('jsonwebtoken')
const fs = require('fs')
const appleId = 'com.your.service.id.here'
const keyId = 'XXXXXXXXXX' // 10 chars, your generated apple key id
const teamId = 'ZZZZZZZZZZ'
const privateKey = fs.readFileSync('YOUR-PATH-HERE.p8')
const secret = jwt.sign(
{
iss: teamId,
iat: Math.floor(Date.now() / 1000),
exp: Math.floor(Date.now() / 1000) + ( 86400 * 180 ), // 6 months
aud: 'https://appleid.apple.com',
sub: appleId
}, privateKey, {
algorithm: 'ES256',
keyid: keyId
})
console.log(secret)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment