Created
November 17, 2022 23:56
-
-
Save dlazares/c68fec4b0fa05a631a5452e8a050cd57 to your computer and use it in GitHub Desktop.
Apple oauth token generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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