parse-community / parse-server-push-adapter

A push notification adapter for Parse Server
https://parseplatform.org
MIT License
87 stars 99 forks source link

APNS TypeError: Cannot read property 'key' of undefined #24

Closed jlhonora closed 8 years ago

jlhonora commented 8 years ago

When trying to send a notification through APNS, I get the following crash:

verbose: sending push to 1 installations
  apn Initialising connection +0ms
  apn Loading Credentials +23ms
  apn 1 left to send +8ms
  apn Module initialisation error: +122ms [TypeError: Cannot read property 'key' of undefined]
  apn Raising error: +0ms 513 { encoding: 'utf8',
  payload: 
   { action: 'redacted',
     type: 'chat',
     message: 'Test message 18:38:29',
     payload: 
      { id: 1,
        body: 'Test message 18:38:29',
        sent_by: 'Joses-MacBook-Pro.local',
        source: 'web',
        sent_at: '2016-06-23 18:38:29' },
     aps: 
      { badge: undefined,
        sound: undefined,
        alert: undefined,
        'content-available': 1,
        'url-args': undefined,
        category: undefined } },
  expiry: undefined,
  priority: 10,
  retryLimit: -1,
  device: undefined,
  compiled: '{"action":"me.beelink.beetrack2.PUSH_NOTIFICATION","type":"chat","message":"Test message 18:38:29","payload":{"id":1,"body":"Test message 18:38:29","sent_by":"Joses-MacBook-Pro.local","source":"web","sent_at":"2016-06-23 18:38:29"},"aps":{"content-available":1}}',
  truncateAtWordEnd: false,
  _contentAvailable: 1 } Device {
  token: <Buffer redacted>,
  connIndex: 0,
  appIdentifier: 'redacted',
  callback: [Function] }
  apn Initialising connection +3ms
  apn Loading Credentials +0ms
  apn 1 left to send +1ms
/Users/jlh/dev/web/parse_server/node_modules/parse-server/lib/ParseServer.js:351
            throw err;
            ^

TypeError: Cannot read property 'key' of undefined
    at validateCredentials (/Users/jlh/dev/web/parse_server/node_modules/parse-server/node_modules/parse-server-push-adapter/node_modules/apn/lib/credentials/validate.js:6:51)
    at /Users/jlh/dev/web/parse_server/node_modules/parse-server/node_modules/parse-server-push-adapter/node_modules/apn/lib/connection.js:163:5
    at _fulfilled (/Users/jlh/dev/web/parse_server/node_modules/parse-server/node_modules/parse-server-push-adapter/node_modules/apn/node_modules/q/q.js:834:54)
    at self.promiseDispatch.done (/Users/jlh/dev/web/parse_server/node_modules/parse-server/node_modules/parse-server-push-adapter/node_modules/apn/node_modules/q/q.js:863:30)
    at Promise.promise.promiseDispatch (/Users/jlh/dev/web/parse_server/node_modules/parse-server/node_modules/parse-server-push-adapter/node_modules/apn/node_modules/q/q.js:796:13)
    at /Users/jlh/dev/web/parse_server/node_modules/parse-server/node_modules/parse-server-push-adapter/node_modules/apn/node_modules/q/q.js:604:44
    at runSingle (/Users/jlh/dev/web/parse_server/node_modules/parse-server/node_modules/parse-server-push-adapter/node_modules/apn/node_modules/q/q.js:137:13)
    at flush (/Users/jlh/dev/web/parse_server/node_modules/parse-server/node_modules/parse-server-push-adapter/node_modules/apn/node_modules/q/q.js:125:13)
    at doNTCallback0 (node.js:407:9)
    at process._tickDomainCallback (node.js:377:13)

Here's the gist of our config:

var api = new ParseServer({
  databaseURI: e.DATABASE_URI,
  appId: e.APP_ID,
  masterKey: e.MASTER_KEY,
  serverURL: e.SERVER_URL,
  verbose: true,
  push: {
    android: {
      senderId: e.ANDROID_SENDER_ID,
      apiKey: e.ANDROID_API_KEY
    },
    ios: [
      {
        pfx: __dirname + '/config/' + e.IOS_PFX_DEV,
        bundleId: e.IOS_BUNDLE_ID_DEV,
        production: false
      },
      {
        pfx: __dirname + '/config/' + e.IOS_PFX_PRO,
        bundleId: e.IOS_BUNDLE_ID_PRO,
        production: true
      }
    ]
  }
});

And the request I'm testing with:

curl \
  -vvv \
    --connect-timeout 4 \
  -X POST \
  -H "X-Parse-Master-Key: $MASTER_KEY" \
  -H "X-Parse-Application-Id: $APPLICATION_ID" \
  -H "Content-Type: application/json" \
  -d "{
        \"channels\": [
          \"$CHANNEL\"
        ],
        \"data\": {
          \"action\": \"me.beelink.beetrack2.PUSH_NOTIFICATION\",
          \"type\": \"chat\",
          \"message\": \"$MESSAGE\",
          \"payload\": $PAYLOAD,
                    \"content-available\": 1
        }
      }" \
    --url "$URL"

The project can be found here: https://github.com/Beetrack/parse_server

I'm really clueless on what I might be doing wrong, any help is greatly appreciated.

flovilmart commented 8 years ago

This seems to be an error in the APNS library. Are your p12 files properly loaded on the server? It seem that they are missing from your repository. If they are not committed and you're deploying to heroky, that may explain the error.

Note that the password option is supported so you can safely encrypt the p12 file password in your yaml.enc as well as protect (and commit) your certificates/keys.

jlhonora commented 8 years ago

That was it, thanks a lot!