Hey yall!,
My issue seemed to be a matter of 2 things:
Wrong headers, I was using algorithm instead of alg.
Like @davessabrad mentioned, the date was too high, so a lowered expiration date worked (15 mins)
I suggest carefully reading the Apple docs and seeing how they define things! It's unfortunate because I did not find an example coming from them.
Happy Coding!
const jwt = require('jsonwebtoken');
const fs = require('fs');
const now = Math.round(new Date().getTime() / 1000);
const expirationTime = now + 900; // Set to 15 minutes (900 seconds)
exports.genrateAppStoreJwt = async () => {
// Your credentials from App Store Connect
const keyId = process.env.KEY_ID;
const issuerId = process.env.ISSUER_ID;
const privateKey = fs.readFileSync('YOUR_PATH');
const bundleId = process.env.BUNDLE_ID;
// Create the JWT header and payload
const header = {
'alg': 'ES256',
'kid': keyId,
'typ': 'JWT'
};
const payload = {
"iss": issuerId,
"iat": now,
"exp": expirationTime,
"aud": 'appstoreconnect-v1',
"bid": bundleId,
};
console.log('payload: ', payload);
// Generate the JWT
const token = jwt.sign(payload, privateKey, { header: header, algorithm: 'ES256' });
console.log(`Generated JWT: ${token}`);
return token;
}