AndrewBarba / apns2

Node client for connecting to Apple's Push Notification Service using the new HTTP/2 protocol with JSON web tokens
MIT License
118 stars 32 forks source link

Unable to send message using two different certificates #8

Closed raviten closed 7 years ago

raviten commented 7 years ago

Here following fails with client2

const fs = require('fs');
const APNS = require('apns2');
const SilentNotification = APNS.SilentNotification;

deviceToken = "ce7b3d45f8b280873e6111e603e4981594db971d59df4065dd57edb7eabf2502"
topic = "com.raviteja.first"
client = new APNS({
  cert: fs.readFileSync('/home/raviteja/pem/first-cert.pem'),
  key: fs.readFileSync('/home/raviteja/pem/first-key.pem')
});
sn = new SilentNotification(deviceToken, {topic:topic});
client.send(sn).then(function(){console.log("success")}).catch(function(err){console.log(JSON.stringify(err));})

deviceToken2 = "b8269494bae819b09572b2874b804d987b0c5545ada6ec9da55fbd4ba489e46e"
topic2 = "com.raviteja.second"

client2 = new APNS({
  cert: fs.readFileSync('/home/raviteja/pem/second-cert.pem'),
  key: fs.readFileSync('/home/raviteja/pem/second-key.pem')
});
sn2 = new SilentNotification(deviceToken2, {topic: topic2});
client2.send(sn2).then(function(){console.log("success")}).catch(function(err){console.log(JSON.stringify(err));})

client.send(sn) => success client.send(sn) => DeviceTokenNotForTopic client2.send(sn) => success As call client2.send(sn2).then(function(){console.log("success")}).catch(function(err){console.log(JSON.stringify(err));}) fails, but client2.send(sn).then(function(){console.log("success")}).catch(function(err){console.log(JSON.stringify(err));}) is successful. This points that client2 is not actually using its own credentials but using client's credentials.

AndrewBarba commented 7 years ago

Huh interesting. This might have to do with the shared http agent. I will look into this tonight

raviten commented 7 years ago

Hi @AndrewBarba, Is there any work around for this?

Thanks, Ravi

AndrewBarba commented 7 years ago

Hey @Black-Star I just released version 1.4.0, can you give latest version a try?

raviten commented 7 years ago

Thanks @AndrewBarba It's working