Error - Insufficient credentials while making the connection for push notification

803 views Asked by At

I am trying to deliver push notification in my ios app and i user node.js. So I am followint the tutorial from the link: https://blog.engineyard.com/2013/developing-ios-push-notifications-nodejs.

In this tutorial they are keeping the passphrase for the private key as empty. But I am setting a password for my private key and I dont know how to include my password in the coding. I know there has been many angles of answer to this. But am not getting anything works. I tried :

.set('cert file', join(__dirname, '../_cert/apn-dev-cert.pem'))
.set('key file', join(__dirname, '../_cert/apn-dev-key.pem'))
//or this works too:
// .set('pfx file', join(__dirname, '../_cert/Certificates.p12'))
// .set('passphrase', 'your passphrase')
.enable('sandbox')



agent.on('message:error', function (err, msg) {
  connect.log('error1');
  switch (err.name) {

// This error occurs when Apple reports an issue parsing the message.
case 'GatewayNotificationError':
  console.log('[message:error] GatewayNotificationError: %s', err.message);


  // The err.code is the number that Apple reports.
  // Example: 8 means the token supplied is invalid or not subscribed
  // to notifications for your application.
  if (err.code === 8) {        
    console.log('    > %s', msg.device().toString());
    // In production you should flag this token as invalid and not
    // send any futher messages to it until you confirm validity
  }

  break;

// This happens when apnagent has a problem encoding the message for transfer
case 'SerializationError':
  console.log('[message:error] SerializationError: %s', err.message);

  break;

// unlikely, but could occur if trying to send over a dead socket
default:
  console.log('[message:error] other error: %s', err.message);      
  break;
  }
});

/*!
 * Make the connection
 */


agent.connect(function (err) {
  // gracefully handle auth problems
  if (err && err.name === 'GatewayAuthorizationError') {

    console.log('Authentication Error: %s', err.message);
    process.exit(1);
  }

  // handle any other err (not likely)
  else if (err) {
    console.log('error1');
    throw err;
  }

  // it worked!
  var env = agent.enabled('sandbox')
    ? 'sandbox'
    : 'production';
  console.log('apnagent [%s] gateway connected', env);
});

I also tried concatenating the certificate and the key and use it as a single file, nothing works.

0

There are 0 answers