Skip to content

Instantly share code, notes, and snippets.

@everm1nd
Last active October 24, 2019 13:49
Show Gist options
  • Save everm1nd/1f0eee4df9d6369da9e0fad3d7529044 to your computer and use it in GitHub Desktop.
Save everm1nd/1f0eee4df9d6369da9e0fad3d7529044 to your computer and use it in GitHub Desktop.
postman-wsse-pre-request.js
// set `wsse-user` and `wsse-secret` variables in
// your Postman environment
const user = pm.environment.get("wsse-user");
const secret = pm.environment.get("wsse-secret");
const header = getWsseHeader(user, secret);
pm.environment.set("wsse-header", header);
function sha1hex(str) {
const hash = CryptoJS.SHA1(str);
return hash.toString(CryptoJS.enc.Hex);
}
function base64Sha1(str) {
const hexDigest = sha1hex(str);
return Buffer.from(hexDigest).toString("base64");
}
function iso8601(time) {
return time.toISOString().split('.')[0] + 'Z';
}
function getWsseHeader(user, secret) {
const timestamp = iso8601(new Date())
const nonceSalt = "I'm your big secret";
const nonce = sha1hex(timestamp + nonceSalt);
const digest = base64Sha1(nonce + timestamp + secret);
return `UsernameToken Username="${user}", PasswordDigest="${digest}", Nonce="${nonce}", Created="${timestamp}"`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment