0

I am creating JWT for talkdesk , I am PHP Developer and talkdesk does not provide JWT creation in PHP , so I have decided to go with Javascript as per documentation I need two packages 'jsonwebtoken' and 'uuid', Which I have installed using NPM, within node_modules directory .

When I call them with require method , I am receiving following error

"Uncaught ReferenceError: require is not defined"

I am note sure how to run this code locally.

// Requires the 'jsonwebtoken' and 'uuid' packages to be installed
var jwt = require('jsonwebtoken');
var uuid = require('uuid/v4');

var private_key = '<client_private_key>'
private_key = "-----BEGIN PRIVATE KEY-----\n" + private_key + "\n-----END 
PRIVATE KEY-----"

var header = {
kid: '<client_key_id>'
}

var payload = {
iss: '<client_id>',
sub: '<client_id>',
aud: 'https://<account_name>.talkdeskid.com/oauth/token',
jti: uuid(),
exp: Math.floor(Date.now() / 1000) + 300,
iat: Math.floor(Date.now() / 1000)
}

token = jwt.sign(payload, private_key, {header: header, algorithm: 
'<client_key_algorith>'})

Any help would highly appreciated.

arvindpundir
  • 136
  • 1
  • 12

0 Answers0