Currently using Rider HTTP Client Plugin as documented here to build out some API test scripts and sample calls. For one of the tests I need to build a JWT token in the Pre-Rquest Script and after many failed attempts I post this question.
this is my current script, have tried a few diff variations with no luck.
let header = JSON.stringify({"alg": "HS512"});
let body = JSON.stringify({
"username": request.environment.get('the_big_username'),
"entity": request.environment.get('the_big_entity'),
"datetime": new Date().toISOString()
});
let theBigSecret = request.environment.get("the_big_secret");
let theHeader = crypto.sha512()
.updateWithText(header)
.digest()
.toBase64(true)
let theBody = crypto.sha512()
.updateWithText(body)
.digest()
.toBase64(true)
const content = `${theHeader}.${theBody}`
let theSignature = encodeURIComponent(crypto.hmac.sha512()
.withTextSecret(theBigSecret)
.updateWithText(content)
.digest()
.toBase64(true))
const allTogetherNow = `${content}.${theSignature}`
// pm.globals.set('jws', signedJws);
request.variables.set('the_big_token', allTogetherNow);
so far all results fail and are not decodable by jwt.io and after much searching and documentation reading I have not gotten any closer to understanding where I am going wrong.