-
-
Save rgr2k/ca7b1120c2cdd3afd6278325e21a1096 to your computer and use it in GitHub Desktop.
Postman pre-request script for Joyent Signature Authentication Scheme
This file contains hidden or 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