This is how I am importing the APNS certificate and private key.
const fs = require("fs");
const path = require("path");
// including APNS certificate file
const certificatePath = path.join(
__dirname,
"../../certificates/apns-certificate.p12"
);
const privateKeyPath = path.join(
__dirname,
"../../certificates/apns-private-key.p8"
);
// to read the files
async function readCertificateAndPrivateKey(certificatePath, privateKeyPath) {
try {
const certificate = await fs.promises.readFile(certificatePath);
const privateKey = await fs.promises.readFile(privateKeyPath, "utf8");
return [certificate, privateKey];
} catch (err) {
console.error(err);
throw new Error("Failed to read certificate or private key" + err);
}
}
This is how I am setting up Create Platform Application parameters
// setting parameters for IOS
const [certificate, privateKey] =
await readCertificateAndPrivateKey(
certificatePath,
privateKeyPath
);
createPlatformApplicationParams.Name = "BeeMobileAppIOS";
createPlatformApplicationParams.Platform = "APNS";//APNS_SANDBOX
createPlatformApplicationParams.Attributes = {
PlatformCredential: privateKey,
PlatformPrincipal: certificate
};
// to create platform application
const platformAppData = await createPlatformApplication(
sns,
createPlatformApplicationParams
);
But it is giving following error:
'$fault': 'client',
'$metadata': {
httpStatusCode: 400,
requestId: '694b59a5-9dfa-5757-8e7d-055f1489b77d',
extendedRequestId: undefined,
cfId: undefined,
attempts: 1,
totalRetryDelay: 0
},
Error: {
Type: 'Sender',
Code: 'InvalidParameter',
Message: 'Invalid parameter: PlatformPrincipal is not a valid Apple certificate.',
message: 'Invalid parameter: PlatformPrincipal is not a valid Apple certificate.'
},
RequestId: '694b59a5-9dfa-5757-8e7d-055f1489b77d',
xmlns: 'http://sns.amazonaws.com/doc/2010-03-31/'
}
So I want to ask, can I use the p12 file as PlatformPrincipal?
I tried the p12 file using AWS console and it worked, but when I implement this in Node JS, it is giving PlatformPrincipal is not a valid Apple certificate error.
After that, I converted p12 certificate into .pem format, and then I try to create Application Platform, but this time it throws a different error:
'$fault': 'client',
'$metadata': {
httpStatusCode: 400,
requestId: '5fefe7bb-9001-54f9-ba3a-bb4141726344',
extendedRequestId: undefined,
cfId: undefined,
attempts: 1,
totalRetryDelay: 0
},
Error: {
Type: 'Sender',
Code: 'InvalidParameter',
Message: 'Invalid parameter: Attributes Reason: Platform credentials are invalid',
message: 'Invalid parameter: Attributes Reason: Platform credentials are invalid'
},
RequestId: '5fefe7bb-9001-54f9-ba3a-bb4141726344',
xmlns: 'http://sns.amazonaws.com/doc/2010-03-31/'
}
Can anyone please let me know what mistakes I am making?