vonage-node-code-snippets icon indicating copy to clipboard operation
vonage-node-code-snippets copied to clipboard

Error: secretOrPrivateKey must be an asymmetric key when using RS256

Open AI-General opened this issue 1 year ago • 0 comments

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. (/root/vonage-node-code-snippets/voice/make-call.js:24:14)

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?

AI-General avatar Jan 15 '24 06:01 AI-General