Created
September 30, 2016 17:08
-
-
Save compwright/ae576210641d497a1705d542706b5973 to your computer and use it in GitHub Desktop.
Postman pre-request script for Joyent Signature Authentication Scheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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