Skip to content

Instantly share code, notes, and snippets.

@compwright
Created September 30, 2016 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save compwright/ae576210641d497a1705d542706b5973 to your computer and use it in GitHub Desktop.
Save compwright/ae576210641d497a1705d542706b5973 to your computer and use it in GitHub Desktop.
Postman pre-request script for Joyent Signature Authentication Scheme
// Postman pre-request script for Joyent Signature Authentication
// (https://github.com/joyent/node-http-signature/blob/master/http_signing.md)
//
// Set the following vars in your Postman environment:
// apiHost
// apiKey
// apiSecret
//
// Set the following headers in Postman (copy/paste):
// Authorization: Signature keyId="{{apiKey}}",algorithm="hmac-sha256",headers="host date",signature="{{signature}}"
// Date: {{date}}
//
// Add the following pre-request script (copy/paste):
const apiSecret = postman.getEnvironmentVariable('apiSecret');
const host = postman.getEnvironmentVariable('apiHost');
const date = new Date().toUTCString();
var signStr = [
'host: ' + host,
'date: ' + date
].join("\n");
var signature = CryptoJS.HmacSHA256(signStr, apiSecret).toString(CryptoJS.enc.Base64);
postman.setGlobalVariable("date", date);
postman.setGlobalVariable("signature", signature);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment