vonage-node-code-snippets
vonage-node-code-snippets copied to clipboard
Error: secretOrPrivateKey must be an asymmetric key when using RS256
When I am running code https://github.com/Vonage/vonage-node-code-snippets/blob/master/voice/make-call.js, I found following error
Error: secretOrPrivateKey must be an asymmetric key when using RS256
at module.exports (/root/vonage-node-code-snippets/node_modules/jsonwebtoken/sign.js:130:22)
at tokenGenerate (/root/vonage-node-code-snippets/node_modules/@vonage/jwt/dist/tokenGenerate.js:97:12)
at Auth.createBearerHeader (/root/vonage-node-code-snippets/node_modules/@vonage/auth/dist/auth.js:140:54)
at Voice.addAuthenticationToRequest (/root/vonage-node-code-snippets/node_modules/@vonage/server-client/dist/client.js:82:52)
at Voice.prepareRequest (/root/vonage-node-code-snippets/node_modules/@vonage/server-client/dist/client.js:256:30)
at Voice.sendRequest (/root/vonage-node-code-snippets/node_modules/@vonage/server-client/dist/client.js:212:34)
at Voice.sendRequestWithData (/root/vonage-node-code-snippets/node_modules/@vonage/server-client/dist/client.js:196:27)
at Voice.sendPostRequest (/root/vonage-node-code-snippets/node_modules/@vonage/server-client/dist/client.js:169:21)
at Voice.createOutboundCall (/root/vonage-node-code-snippets/node_modules/@vonage/voice/dist/voice.js:202:33)
at Object.
This error occured on following code snippet:
const vonage = new Vonage({ apiKey: VONAGE_API_KEY, apiSecret: VONAGE_API_SECRET, applicationId: VONAGE_APPLICATION_ID, privateKey: privateKey, })
const vonage = new Vonage({ apiKey: VONAGE_API_KEY, apiSecret: VONAGE_API_SECRET, applicationId: VONAGE_APPLICATION_ID, privateKey: VONAGE_APPLICATION_PRIVATE_KEY_PATH })
Possible Solution
const privateKey = fs.readFileSync(VONAGE_APPLICATION_PRIVATE_KEY_PATH);
const vonage = new Vonage({ apiKey: VONAGE_API_KEY, apiSecret: VONAGE_API_SECRET, applicationId: VONAGE_APPLICATION_ID, privateKey: privateKey, })
My question
Is it same in feature?