Get any file that's not an apple authentication key
Create a new apn.Provider using that file
Sample code:
// Not a valid .p8 file
let randomFile = fs.readFileSync(path.join(__dirname, "test_token.js"));
let apnProdOptions = {
token: {
key: randomFile,
keyId: validKeyId,
teamId: validTeamId
},
production: true,
hideExperimentalHttp2Warning: true
}
let provider = new apn.Provider(apnProdOptions);
Expected/apn results:
An error message would be thrown to let you know that your provider will be unusable:
{ VError: Failed to generate token: error:0906D06C:PEM routines:PEM_read_bio:no start line
at prepareToken (/...my_path.../node_modules/apn/lib/credentials/token/prepare.js:45:13)
at config (/...my_path.../node_modules/apn/lib/config.js:43:31)
at new Client (/...my_path.../node_modules/apn/lib/client.js:11:19)
at new Provider (/...my_path.../node_modules/apn/lib/provider.js:12:19)
at addApnProviderForAuthKey (/...my_path.../models/authenticationKey.js:1:18523)
at AuthenticationKey.create.then.newAuthKey (/...my_path.../models/authenticationKey.js:1:14170)
at tryCatcher (/...my_path.../node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/...my_path.../node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/...my_path.../node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromise0 (/...my_path.../node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/...my_path.../node_modules/bluebird/js/release/promise.js:693:18)
at Async._drainQueue (/...my_path.../node_modules/bluebird/js/release/async.js:133:16)
at Async._drainQueues (/...my_path.../node_modules/bluebird/js/release/async.js:143:10)
at Immediate.Async.drainQueues (/...my_path.../node_modules/bluebird/js/release/async.js:17:14)
at runCallback (timers.js:789:20)
at tryOnImmediate (timers.js:751:5)
at processImmediate [as _immediateCallback] (timers.js:722:5)
jse_shortmsg: 'Failed to generate token',
jse_cause: Error: error:0906D06C:PEM routines:PEM_read_bio:no start line
at Sign.sign (crypto.js:331:26)
at sign (/...my_path.../node_modules/jwa/index.js:55:45)
at Object.sign (/...my_path.../node_modules/jwa/index.js:75:27)
at Object.jwsSign [as sign] (/...my_path.../node_modules/jws/lib/sign-stream.js:23:24)
at module.exports (/...my_path.../node_modules/jsonwebtoken/sign.js:186:16)
at prepareToken (/...my_path.../node_modules/apn/lib/credentials/token/prepare.js:27:18)
at config (/...my_path.../node_modules/apn/lib/config.js:43:31)
at new Client (/...my_path.../node_modules/apn/lib/client.js:11:19)
at new Provider (/...my_path.../node_modules/apn/lib/provider.js:12:19)
Actual/node-apn-http2
No error message, the provider is created.
Let me know if I can provide any more details to be helpful! For now, we're just using apn to validate and then tossing away the provider, so we'd love to be able to completely get rid of that dependency!
Steps to reproduce
apn.Provider
using that fileSample code:
Expected/
apn
results:An error message would be thrown to let you know that your provider will be unusable:
Actual/
node-apn-http2
No error message, the provider is created.
Let me know if I can provide any more details to be helpful! For now, we're just using
apn
to validate and then tossing away the provider, so we'd love to be able to completely get rid of that dependency!