Skip to content

Instantly share code, notes, and snippets.

@david-bc
Created September 7, 2017 16:31
Show Gist options
  • Save david-bc/7cdb7bcacc7d94808454fed33345b7eb to your computer and use it in GitHub Desktop.
Save david-bc/7cdb7bcacc7d94808454fed33345b7eb to your computer and use it in GitHub Desktop.
Postman Pro Blog Snippets
function get_path() {
var resolvedUrl = request.url.replace(/{{(\w*)}}/g,function(str,key) {return getFromEnv(key)});
return /.+?\:\/\/.+?(\/.+?)(?:# \? $)/.exec(resolvedUrl)[1]
}
function auth_string(version, lookup, signature) {
return // a secret formula
}
function getFromEnv(key) {
return environment[key] ? environment[key] : postman.getGlobalVariable(key);
}
var date = new Date().toISOString();
var message = // a secret formula
var secret = getFromEnv(“hmac_secret”);
if (secret) {
var hmacKey = getFromEnv(“hmac_key”);
var version = “BC1-HMAC-SHA256”;
var hash = CryptoJS.HmacSHA256(message, secret);
var signature = CryptoJS.enc.Base64.stringify(hash);
var authorization = auth_string(version, hmacKey, signature)
postman.setEnvironmentVariable(“authorization”, authorization);
postman.setEnvironmentVariable(“date”, date);
} else {
console.log(“Environment variable \”hmac_secret\” must be set.”)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment