내용으로 건너뛰기

Setting up AWS SNS for IOS using Node JS

0

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?

질문됨 3년 전610회 조회
1개 답변
0

To resolve platform credential errors, Kindly follow the below steps.

Important: Before completing the following steps, check the provider certificate type in your Apple Developer account. Then, download the certificate.

  1. Open the Amazon SNS console.
  2. On the navigation pane, choose Push notifications.
  3. Choose Create platform application.
  4. For Application name, enter a name for your application.
  5. For Push notification platform, select Apple iOS/VoIP/Mac.
  6. In the Apple Credentials section, select the Used for development in sandbox check box if you're using a certificate of type Sandbox.

Important: You must not select this check box if you're using a certificate of type Sandbox & Production. Otherwise, you receive an error.

  1. For Push certificate type, select your type of certificate.
  2. Choose Choose file, and then select the certificate that you want to load credentials from.
  3. Choose Create platform application.

Reference - https://repost.aws/knowledge-center/sns-invalid-parameter-error-api-call

AWS
전문가
답변함 3년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.