I need to create a JWT(Json Web Token) , I have client credentials token in ES256 algorithm.
Requirement - > https://docs.talkdesk.com/docs/using-a-signed-jwt
SO I have Install Nodejs in local , when I am trying to get this work its giving me error, I am new to javascript. may anyone please help me to get it work.
Error is internal/crypto/sig.js80
const http = require('http');
var jwt = require('jsonwebtoken');
var uuid = require('uuid/v4');
//create a server object:
var private_key = 'private_key goes here'
private_key = "-----BEGIN PRIVATE KEY-----\n" + private_key + "\n-----END PRIVATE KEY-----"
var header = {
kid: 'bdef4554463d8078be9af1d9de55'
}
var payload = {
iss: 'a57bb14a44455e98800d6a513953fc0',
sub: 'a57bb14a445541e98800d6a513953fc0',
aud: 'https://c2performdev.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: 'ES256'})
There is issue with the key. The same code works fine if key is ok.
var fs = require("fs");
const http = require("http");
var jwt = require("jsonwebtoken");
var uuid = require("uuid/v4");
//create a server object:
var jwt = require("jsonwebtoken");
var private_key = fs.readFileSync("./private.pem");
var header = {
kid: "bdef4554463d8078be9af1d9de55"
};
var payload = {
iss: "a57bb14a44455e98800d6a513953fc0",
sub: "a57bb14a445541e98800d6a513953fc0",
aud: "https://c2performdev.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: "ES256" });
console.log(token);
I following command to generate key in mac.
openssl ecparam -genkey -name secp256k1 -noout -out private.pem
openssl ec -in private.pem -pubout -out public.pem
the body is key file is as follows.
-----BEGIN EC PRIVATE KEY-----
MHQCAQEEICu0QorVDVCvfc9JeiDlUxK4IJnx69vxOwLYZsPtVcmToAcGBSuBBAAK
oUQDQgAEQi9ENvV3eiN/hVed5eBqOTUa5v+olsdHk51RZbJNT7Rwz42tNSMrzucr
Jhn7xIOvQgw0NH5Tad+BE7ybIakSUg==
-----END EC PRIVATE KEY-----
this does not match what you have done. Try correcting the key structure.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.