Sunday, March 22, 2026

Method : GET 

URL : https://raw.githubusercontent.com/kjur/jsrsasign/master/jsrsasign-all-min.js

Post Response Script : 

// This saves the library code into a global variable named 'jsrsasign_code'
pm.globals.set("jsrsasign_code", pm.response.text());

// This script runs AFTER the response is received
if (pm.response.code === 200) {
    // pm.response.text() gets the raw library code from the response body
    pm.globals.set("jsrsasign_code", pm.response.text());
    console.log("Library stored successfully!");
}





Postman - JS Script to generate JWT assertion

const jsrsasign_code = pm.globals.get("jsrsasign_code");

var navigator = {}; 

var window = {}; 

eval(jsrsasign_code); 


// 2. Format the Private Key (Removes extra spaces/hidden characters)

let rawKey = pm.environment.get("privateKey");

const privateKey = rawKey.replace(/\\n/g, '\n');


// 3. Define Header and Payload

const header = { alg: 'RS256', typ: 'JWT' };

const payload = {

    iss: pm.environment.get("vasuclientId"),

    sub: pm.environment.get("vasuusername"),

    aud: pm.environment.get("loginUrl"),

    exp: Math.floor(Date.now() / 1000) + 900 

};


// 4. Generate the Signed Assertion

const sHeader = JSON.stringify(header);

const sPayload = JSON.stringify(payload); 


// This specific method produces the compact JWT string Salesforce expects

const signedAssertion = KJUR.jws.JWS.sign("RS256", sHeader, sPayload, privateKey);


// 5. CRITICAL: Clean the string for the Body

// Ensures no stray spaces or hidden characters are sent to Salesforce

pm.variables.set("jwt_assertion", signedAssertion.trim());