Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse Server Push giving APNS 513 #697

Closed
AlecKriebel opened this issue Feb 27, 2016 · 29 comments
Closed

Parse Server Push giving APNS 513 #697

AlecKriebel opened this issue Feb 27, 2016 · 29 comments

Comments

@AlecKriebel
Copy link

Hi all,

I'm getting an issue when trying to send push notifications over Parse Server using cloud code, specifically, the heroku server is spitting a 513 APNS at me. This was triggered by calling the cloud function on the iOS client-side.

I've discluded my keys and urls, etc, so they are in ALL_CAPS.

What do I need to do to make Push notification work on my parse server? Is there an issue with my .p12?

Here is my cloud function:

Parse.Cloud.define('test', function(req, res) {
    Parse.Push.send({
        channels: ['global'],
        data: {
            alert: 'Test',
            badge: 1,
            sound: 'default'
        }
    }, {
        success: function() {
            console.log('##### PUSH OK');
        },
        error: function(error) {
            console.log('##### PUSH ERROR' + error.message);
        },
        useMasterKey: true
    });
});

Here is my Index.js setup:

var express = require('express');
var ParseServer = require('parse-server').ParseServer;

var databaseUri = process.env.DATABASE_URI || process.env.MONGOLAB_URI;

if (!databaseUri) {
  console.log('DATABASE_URI not specified, falling back to localhost.');
}

var api = new ParseServer({
  databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  appId: process.env.APP_ID || 'APP_ID',
  masterKey: process.env.MASTER_KEY || 'MATER_KEY', //Add your master key here. Keep it secret!
  clientKey: 'CLIENT_KEY',
  serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse',
  push:{
    ios: {
            pdx: '/Users/AlecKriebel/Desktop/ParsePush.p12', // the path and filename to the .p12 file you exported earlier. 
            bundleId: 'BUNDLE-ID', 
            production: false
        }
  }
});
// Client-keys like the javascript key or the .NET key are not necessary with parse-server
// If you wish you require them, you can set them as options in the initialization above:
// javascriptKey, restAPIKey, dotNetKey, clientKey

var app = express();

// Serve the Parse API on the /parse URL prefix
var mountPath = process.env.PARSE_MOUNT || '/parse';
app.use(mountPath, api);

// Parse Server plays nicely with the rest of your web routes
app.get('/', function(req, res) {
  res.status(200).send('I dream of being a web site.');
});

var port = process.env.PORT || 1337;
app.listen(port, function() {
    console.log('parse-server-example running on port ' + port + '.');
});

Here is the server response:

2016-02-27T09:21:13.320224+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=POST path="/parse/functions/test" host=SERVER_URL request_id=e35a7606-e3e5-4303-a546-b6b604466f01 fwd="174.77.32.122" dyno=web.1 connect=1ms service=637ms status=503 bytes=0
2016-02-27T09:21:13.220879+00:00 app[web.1]: ##### PUSH OK
2016-02-27T09:21:13.322808+00:00 app[web.1]:         sound: 'default',
2016-02-27T09:21:13.322811+00:00 app[web.1]:         category: undefined } },
2016-02-27T09:21:13.322799+00:00 app[web.1]: APNS Notification caused error: 513 for device  Device {
2016-02-27T09:21:13.322803+00:00 app[web.1]:   token: <Buffer bf 90 0f e6 c5 85 85 cb 32 b8 d1 73 65 ce e8 61 3a 13 2d 98 be 3f 1d 50 14 68 a6 f9 c6 0d 68 95>,
2016-02-27T09:21:13.322804+00:00 app[web.1]:   connIndex: 0,
2016-02-27T09:21:13.322809+00:00 app[web.1]:         alert: 'Test',
2016-02-27T09:21:13.322810+00:00 app[web.1]:         'url-args': undefined,
2016-02-27T09:21:13.322806+00:00 app[web.1]:   appIdentifier: 'BUNDLE-ID' } { encoding: 'utf8',
2016-02-27T09:21:13.322806+00:00 app[web.1]:   payload: 
2016-02-27T09:21:13.322808+00:00 app[web.1]:       { badge: 1,
2016-02-27T09:21:13.322814+00:00 app[web.1]:   compiled: '{"aps":{"badge":1,"sound":"default","alert":"Test"}}',
2016-02-27T09:21:13.322807+00:00 app[web.1]:    { aps: 
2016-02-27T09:21:13.323511+00:00 app[web.1]: APNS can not find vaild connection for {"type":"Buffer","data":[191,144,15,230,197,133,133,203,50,184,209,115,101,206,232,97,58,19,45,152,190,63,29,80,20,104,166,249,198,13,104,149]}
2016-02-27T09:21:13.322812+00:00 app[web.1]:   expiry: undefined,
2016-02-27T09:21:13.322815+00:00 app[web.1]:   truncateAtWordEnd: false,
2016-02-27T09:21:13.322812+00:00 app[web.1]:   priority: 10,
2016-02-27T09:21:13.353632+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-02-27T09:21:13.354248+00:00 app[web.1]: npm ERR! npm  v3.6.0
2016-02-27T09:21:13.322813+00:00 app[web.1]:   retryLimit: -1,
2016-02-27T09:21:13.353835+00:00 app[web.1]: npm ERR! node v5.6.0
2016-02-27T09:21:13.322813+00:00 app[web.1]:   device: undefined,
2016-02-27T09:21:13.353332+00:00 app[web.1]: npm ERR! Linux 3.13.0-77-generic
2016-02-27T09:21:13.355041+00:00 app[web.1]: npm ERR! Exit status 1
2016-02-27T09:21:13.322817+00:00 app[web.1]:   _sound: 'default' }
2016-02-27T09:21:13.355376+00:00 app[web.1]: npm ERR! Failed at the parse-server-example@1.1.0 start script 'node index.js'.
@jaydeep82
Copy link

@AlecKriebel
It seems like issue with .p12 files. You need to create p12 files without password and use it here.

Please let me know if you still have same error.

@AlecKriebel
Copy link
Author

@jaydeep82 I've been using .p12 files without passwords.

I've even tried including both a development AND production .p12 and it has not worked.

It is worth noting that I have the exact same .p12 in Parse and push notifications work there, but not in my Heroku/MongoDB parse-server.

@jaydeep82
Copy link

@AlecKriebel

Did you also push the .p12 files in heroku using git command ? I think node.js could not find the p12 file in specified location.

For me, I have keep MyParsePush.p12 at same location of index.js.

push:{
    ios: {
            pdx: 'MyParsePush.p12',
            bundleId: 'BUNDLE-ID', 
            production: false
        }
  }

Please let me know if you still have same error.

@AlecKriebel
Copy link
Author

@jaydeep82

After I posted this, I changed it to be that. My Index.js is now:

  push:{
    ios: [
      {
             pdx: __dirname + '/ParsePush.p12', 
             bundleId: 'BUNDLE-ID', 
             production: false
          }, {
        pdx: __dirname + '/APNSDistribution.p12',
        bundleId: 'BUNDLE-ID', 
        production: true
      }
    ]
  }
});

And here is the git directory that has been pushed:
screen shot 2016-03-03 at 10 11 28 pm

With this config it still does not work. Do you think I should remove the __dirname before the file in my index.js?

@jaydeep82
Copy link

@AlecKriebel

Yes, please remove the _dirname and use as below :

  push:{
    ios: [
      {
             pdx: 'ParsePush.p12', 
             bundleId: 'BUNDLE-ID', 
             production: false
          }, {
        pdx: 'APNSDistribution.p12',
        bundleId: 'BUNDLE-ID', 
        production: true
      }
    ]
  }
});

I've removed '/' also.

Then push the change to heroku using git and check again.
Hope this will work.

@AlecKriebel
Copy link
Author

@jaydeep82

This still does not work after making this change.

Index.js:

  push:{
    ios: [
      {
             pdx: 'ParsePush.p12', // the path and filename to the .p12 file you exported earlier. 
             bundleId: 'BUNDLE-ID', 
             production: false
          }, {
        pdx: 'APNSDistribution.p12',
        bundleId: 'BUNDLE-ID', 
        production: true
      }
    ]
  }

Pushed git directory:
screen shot 2016-03-04 at 11 49 07 am

Heroku Logs after attempting to push:
at=info method=POST path="/parse/events/AppOpened" host=HOST_NAME request_id=d4300064-3482-4fc1-b22d-9e7c29a8b047 fwd="169.234.104.61" dyno=web.1 connect=1ms service=30ms status=200 bytes=468
2016-03-04T19:45:31.360036+00:w00 heroku[router]: at=info method=POST path="/parse/push" host=HOST_NAME request_id=5f7d6bff-67ed-43a9-b223-aa2ba61b4f18 fwd="54.242.85.214" dyno=web.1 connect=0ms service=8ms status=200 bytes=482
2016-03-04T19:45:31.367715+00:00 app[web.1]: ##### PUSH OK
2016-03-04T19:45:31.434846+00:00 app[web.1]: Can not find sender for push type android, {"where":{"deviceType":"ios"},"data":{"alert":"Test","badge":1,"sound":"default"}}
2016-03-04T19:45:31.453647+00:00 app[web.1]: APNS Notification caused error: 513 for device  Device {
2016-03-04T19:45:31.453663+00:00 app[web.1]:   token: <Buffer bf 90 0f e6 c5 85 85 cb 32 b8 d1 73 65 ce e8 61 3a 13 2d 98 be 3f 1d 50 14 68 a6 f9 c6 0d 68 95>,
2016-03-04T19:45:31.453664+00:00 app[web.1]:   connIndex: 0,
2016-03-04T19:45:31.453666+00:00 app[web.1]:   payload: 
2016-03-04T19:45:31.453665+00:00 app[web.1]:   appIdentifier: 'APP-ID } { encoding: 'utf8',
2016-03-04T19:45:31.453667+00:00 app[web.1]:    { aps: 
2016-03-04T19:45:31.453668+00:00 app[web.1]:       { badge: 1,
2016-03-04T19:45:31.453668+00:00 app[web.1]:         sound: 'default',
2016-03-04T19:45:31.453669+00:00 app[web.1]:         alert: 'Test',
2016-03-04T19:45:31.453670+00:00 app[web.1]:         'url-args': undefined,
2016-03-04T19:45:31.453670+00:00 app[web.1]:         category: undefined } },
2016-03-04T19:45:31.453671+00:00 app[web.1]:   expiry: undefined,
2016-03-04T19:45:31.453672+00:00 app[web.1]:   priority: 10,
2016-03-04T19:45:31.453672+00:00 app[web.1]:   retryLimit: -1,
2016-03-04T19:45:31.453673+00:00 app[web.1]:   device: undefined,
2016-03-04T19:45:31.453674+00:00 app[web.1]:   compiled: '{"aps":{"badge":1,"sound":"default","alert":"Test"}}',
2016-03-04T19:45:31.453675+00:00 app[web.1]:   truncateAtWordEnd: false,
2016-03-04T19:45:31.453675+00:00 app[web.1]:   _alert: 'Test',
2016-03-04T19:45:31.453676+00:00 app[web.1]:   _badge: 1,
2016-03-04T19:45:31.453677+00:00 app[web.1]:   _sound: 'default' }
2016-03-04T19:45:31.455198+00:00 app[web.1]: APNS Notification caused error: 513 for device  Device {
2016-03-04T19:45:31.455214+00:00 app[web.1]:   connIndex: 0,
2016-03-04T19:45:31.455213+00:00 app[web.1]:   token: <Buffer af 56 af 5d eb 71 1a 11 17 dc 9b 2f 9e 8b 35 da ca 75 4b b4 17 18 c5 fd 65 08 12 5a bb f3 91 17>,
2016-03-04T19:45:31.455215+00:00 app[web.1]:   payload: 
2016-03-04T19:45:31.455215+00:00 app[web.1]:   appIdentifier: 'BUNDLE-ID' } { encoding: 'utf8',
2016-03-04T19:45:31.455216+00:00 app[web.1]:    { aps: 
2016-03-04T19:45:31.455216+00:00 app[web.1]:       { badge: 1,
2016-03-04T19:45:31.455218+00:00 app[web.1]:         'url-args': undefined,
2016-03-04T19:45:31.455217+00:00 app[web.1]:         sound: 'default',
2016-03-04T19:45:31.455219+00:00 app[web.1]:   expiry: undefined,
2016-03-04T19:45:31.455217+00:00 app[web.1]:         alert: 'Test',
2016-03-04T19:45:31.455218+00:00 app[web.1]:         category: undefined } },
2016-03-04T19:45:31.455219+00:00 app[web.1]:   priority: 10,
2016-03-04T19:45:31.455220+00:00 app[web.1]:   retryLimit: -1,
2016-03-04T19:45:31.455221+00:00 app[web.1]:   device: undefined,
2016-03-04T19:45:31.455221+00:00 app[web.1]:   compiled: '{"aps":{"badge":1,"sound":"default","alert":"Test"}}',
2016-03-04T19:45:31.455222+00:00 app[web.1]:   truncateAtWordEnd: false,
2016-03-04T19:45:31.455222+00:00 app[web.1]:   _alert: 'Test',
2016-03-04T19:45:31.456950+00:00 app[web.1]: /app/node_modules/parse-server/lib/index.js:288
2016-03-04T19:45:31.455223+00:00 app[web.1]:   _sound: 'default' }
2016-03-04T19:45:31.456964+00:00 app[web.1]:       ^
2016-03-04T19:45:31.455223+00:00 app[web.1]:   _badge: 1,
2016-03-04T19:45:31.456965+00:00 app[web.1]: 
2016-03-04T19:45:31.456963+00:00 app[web.1]:       throw err;
2016-03-04T19:45:31.456965+00:00 app[web.1]: Error: ENOENT: no such file or directory, open 'cert.pem'
2016-03-04T19:45:31.456966+00:00 app[web.1]:     at Error (native)
2016-03-04T19:45:31.471477+00:00 app[web.1]: 
2016-03-04T19:45:31.478682+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-03-04T19:45:31.478289+00:00 app[web.1]: npm ERR! Linux 3.13.0-77-generic
2016-03-04T19:45:31.478928+00:00 app[web.1]: npm ERR! node v5.7.1
2016-03-04T19:45:31.479422+00:00 app[web.1]: npm ERR! npm  v3.6.0
2016-03-04T19:45:31.479758+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2016-03-04T19:45:31.480085+00:00 app[web.1]: npm ERR! Exit status 7
2016-03-04T19:45:31.479936+00:00 app[web.1]: npm ERR! parse-server-example@1.1.0 start: `node index.js`
2016-03-04T19:45:31.480270+00:00 app[web.1]: npm ERR! 
2016-03-04T19:45:31.480432+00:00 app[web.1]: npm ERR! Failed at the parse-server-example@1.1.0 start script 'node index.js'.
2016-03-04T19:45:31.480597+00:00 app[web.1]: npm ERR! Make sure you have the latest version of node.js and npm installed.
2016-03-04T19:45:31.480755+00:00 app[web.1]: npm ERR! If you do, this is most likely a problem with the parse-server-example package,
2016-03-04T19:45:31.480899+00:00 app[web.1]: npm ERR! not with npm itself.
2016-03-04T19:45:31.481003+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2016-03-04T19:45:31.481109+00:00 app[web.1]: npm ERR!     node index.js
2016-03-04T19:45:31.481228+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2016-03-04T19:45:31.481314+00:00 app[web.1]: npm ERR!     npm bugs parse-server-example
2016-03-04T19:45:31.481417+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2016-03-04T19:45:31.485948+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2016-03-04T19:45:31.481521+00:00 app[web.1]: npm ERR!     npm owner ls parse-server-example
2016-03-04T19:45:31.486075+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
2016-03-04T19:45:31.481622+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2016-03-04T19:45:31.485747+00:00 app[web.1]: 
2016-03-04T19:45:31.475155+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=POST path="/parse/functions/test" host=HOST_NAME request_id=81aa0298-7dab-4f38-ae0d-2f533f23fa13 fwd="169.234.104.61" dyno=web.1 connect=4ms service=186ms status=503 bytes=0

@flovilmart
Copy link
Contributor

node-apn/node-apn#123

@AlecKriebel
Copy link
Author

@flovilmart Thanks, that gets me in the right direction, however, this error is still unclear

2016-03-05T03:31:45.778187+00:00 app[web.1]: /app/node_modules/parse-server/lib/index.js:288
2016-03-05T03:31:45.778279+00:00 app[web.1]:       ^
2016-03-05T03:31:45.778313+00:00 app[web.1]: Error: ENOENT: no such file or directory, open 'cert.pem'

As I understand, to authenticate push services a .p12 or a key and cert file in the .cem format is needed. Since I've supplied a .p12, why would the error be that I need a .pem file?

I apologize if this is obvious but, from what I can see, the index.js file is only 262 lines, not 288 or more.

@flovilmart
Copy link
Contributor

Provide the full path of your certificate, that will help. path.resolve(__dirname, certPath) where certPath is the relative path to the certificate from the file you're calling it.

@liennh
Copy link

liennh commented Mar 10, 2016

if you host your own Parse Server on Heroku or AWS, The PFPush is NOT supported. (Said by Parse.com)

@AlecKriebel
Copy link
Author

@liennh Hmmm... I had seen that somewhere, but later heard support had been added. I dont see it on here, do you have a link? Any 3rd party push recommendations?

@liennh
Copy link

liennh commented Mar 10, 2016

@AlecKriebel You are right. Push feature has been added in Parse Server. Perhap your problem is at generating PEM or .P12 file.

I remember that before Parse.com recommended developers to use the Push provider https://onesignal.com/

@pbush25
Copy link

pbush25 commented Mar 13, 2016

I am having the exact same error as @AlecKriebel was. We discussed earlier today, and he had still not come to a resolution for this problem. Between talking to him and using what was here, I attempted to use APNS by setting my environment variables to this:

var developPath = path.resolve(__dirname, 'development_cert.p12');
var distributePath = path.resolve(__dirname, 'production_cert.p12');
var api = new ParseServer({
databaseURI: databaseUri || 'databaseURI',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'myAppId',
masterKey: process.env.MASTER_KEY || '', //Add your master key here. Keep it secret!
serverURL: process.env.SERVER_URL || 'http://localhost:1337',  // Don't forget to change to https if needed
push: {
      ios: [
      {
          pdx: developPath,
          bundleId: 'bundleID',
          production: false
      },
      {
          pdx: distributePath,
          bundleId: 'bundleID',
          production: true
      }
    ]
}
});

With this in my index.js file, I run into the same errors, where Heroku logs say
2016-03-13T03:31:45.778187+00:00 app[web.1]: /app/node_modules/parse-server/lib/index.js:288
2016-03-13T03:31:45.778279+00:00 app[web.1]: ^
2016-03-13T03:31:45.778313+00:00 app[web.1]: Error: ENOENT: no such file or directory, open 'cert.pem'

I spent several hours troubleshooting today but was unable to come to a resolution. I redownloaded my certificates and reexported them too just to make sure, but these were the same I was using on Parse before and they worked without issue. Since two people have run into the same error, this seems like something that needs to be addressed.

@flovilmart
Copy link
Contributor

the key is pfx not pdx

@pbush25
Copy link

pbush25 commented Mar 13, 2016

Wow I'm an idiot. One letter! Thanks @flovilmart!

@flovilmart
Copy link
Contributor

ahah :)

@flovilmart
Copy link
Contributor

Close when you,re done :)

@AlecKriebel
Copy link
Author

@pbush25 @flovilmart I'll be willing to bet that was my issue too, testing now. If it is, I'll probably rip my hair out. Will close after I test.

@pbush25
Copy link

pbush25 commented Mar 13, 2016

Oh believe me, I wanted to rip my hair out too!

@flovilmart
Copy link
Contributor

Is there a typo in the docs?

Just FYI, we're working on upgrading to the new API for APNS over HTTP 2, where a single certificate would work for both dev and production

@pbush25
Copy link

pbush25 commented Mar 13, 2016

I don't see a typo in the the main push docs, but they might be somewhere seeing as two people managed to end up with it.

@AlecKriebel
Copy link
Author

@flovilmart From what I remember, I definitely copied and pasted the initialization code from somewhere, probably the docs at one point.

I know I had been following this setup guide: http://rogerstringer.com/2016/02/11/parse-server-push/
which also uses 'pdx'

@flovilmart
Copy link
Contributor

looking at our docs: https://github.com/ParsePlatform/parse-server/wiki/Push we properly describe with pfx :)

And I can see there are many errors in that tutorial, missing / at the end of the URL for the Android SDK etc...

@pbush25
Copy link

pbush25 commented Mar 13, 2016

Can you clarify for me that using this new version of Parse Push we can no longer send pushes from a client such as the iOS SDK?

@flovilmart
Copy link
Contributor

no, that don,t change the client push sending abilities, for now it's disabled

@pbush25
Copy link

pbush25 commented Mar 13, 2016

So all pushes will have to be set through cloud code now?

@flovilmart
Copy link
Contributor

yes that's right

@pbush25
Copy link

pbush25 commented Mar 13, 2016

Does that include from the PHP SDK also?

@flovilmart
Copy link
Contributor

you can send them from any SDK with masterKey access

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants