Using Apple p8 private keys
Hi,
I am trying to create jws signed with a private key file (.p8) downloaded from apple, when I try to import the key into a keystore I get error: no importer for key
var keyStore = jose.JWK.createKeyStore();
var key = fs.readFileSync('mykey.p8');
await keyStore.add(key, 'pem');
I tried all other forms (private/pkcs8 etc) no luck as well. Is it something that can be done? Thx.
Hi @ValYouW, I am getting the same error. Did you find a solution?
Hi @serdarde
I don't recall exactly my scenario when having this issue, but now all api calls to Apple are done using npm package jws.
Example:
var fs = require('fs'),
jws = require('jws');
const KEY_ID = '2X9R4HXF34'; // Your private key ID from App Store Connect
let bundleId = 'com.mycomp.myapp';
let signKey = fs.readFileSync(p8KeyFile).toString();
const timeNow = Math.floor(Date.now() / 1000) - 60;
var header = { alg: 'ES256', kid: KEY_ID, typ: 'JWT' };
const payload = {
iss: '57246542-96fe-1a63-e053-0824d011072a', // Your issuer ID from the Keys page in App Store Connect
iat: timeNow,
exp: timeNow + 600,
aud: 'appstoreconnect-v1',
bid: bundleId,
};
let signature = jws.sign({ header, payload, secret: signKey });
let headers = {Authorization: `Bearer ${signature}`};
let url = 'https://api.storekit.itunes.apple.com/inApps/v1/lookup/78678657865';
Hi @ValYouW, I have already tried the JWS, but it also doesn't support the curve I want (brainpoolp256r1). Now I am writing it manually. Thank you 🙏🏼