How to use aps.cer file for APN (Push notification) with Node.js?

3k views Asked by At

I'm having issues with node.js sending push notifications, I think because I'm doing something wrong with my APN certificate thats generated in my apple developer account. Im getting this error from Node.js.

VError: Failed to generate token: error:0906D06C:PEM routines:PEM_read_bio:no start line

I'm not sure I've generated the right file in the apple developer account. See below screenshot, when i click download this gives me a "aps.cer" file which is what i'm putting in my node.js project and using with node-app module. Here is how im setting it in my code:

let options = {
        token: {
            key: "aps.cer",
            keyId: "singlemeout.Single-Me-Out",
            teamId: "Team Name"
        },
        production: false
    };

Here is a screen shot of my certificate.

enter image description here

1

There are 1 answers

8
jcaron On BEST ANSWER

You are providing node-apn with a token-based configuration, while you are using certificates.

If you want to keep using certificates:

  • the certificate should be in PEM format.

    You can do the conversion like this:

    openssl x509 -inform DER -in aps.cer -out certificate.pem
    
  • you need to provide the key, either by adding it to the certificate, or by providing it as a separate file

  • you need to use the cert, key and or pfx properties in your config object rather than token.key etc.

    let options = {
            cert: "certificate.pem",
            key: "privatekey.pem"
        };
    

Alternatively, you can switch to using tokens.

See https://github.com/node-apn/node-apn/blob/master/doc/provider.markdown for full details.

Also your production property is not consistent with the certificate used.