Created
October 3, 2017 11:54
-
-
Save ganesshkumar/ce117231967175f288046da7a9a1db41 to your computer and use it in GitHub Desktop.
Making MitterIO App Access Key API calls with Postman
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
// Setup your headers this way (it'd be better if you used Presets for this) | |
// | |
// X-Application-Access-Key : {{mitter_appAccessKey}} | |
// Content-Type : application/json | |
// Date : {{mitter_requestDate}} | |
// Nonce : {{mitter_requestNonce}} | |
// Content-MD5 : {{mitter_requestPayloadMd5}} | |
// Authorization : {{mitter_requestAuthorization}} | |
// Then add the following script as a pre-request script (you will have to create a new environment | |
// when using this script). | |
// This is the exact object you get when you click on 'Copy To Clipboard' in subscriber-ui | |
var access = {"accessKey":{"key":"---"},"accessSecret":{"secret":"---"}}; | |
var dateHeaderValue = (new Date()).toUTCString(); | |
var contentType = request.headers["Content-Type"]; | |
var payload = (request.data ? request.data.toString() : ''); | |
var method = request.method; | |
var path = request.url.match(/^(https?\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/)[5]; | |
// This is of-course not expected to be secure.. don't try to ever use | |
// this in prod. However, if you are, it means you are using JS in prod, | |
// which means you don't work with us anymore, so it's ok in fact | |
var nonce = Math.random().toString(36).substr(2, 12); | |
var contentMd5 = CryptoJS.MD5(payload).toString(CryptoJS.enc.Base64); | |
var digestTarget = [ | |
method.toUpperCase(), | |
contentType, | |
contentMd5, | |
dateHeaderValue, | |
path, | |
nonce | |
].join("\n"); | |
var digest = CryptoJS.HmacSHA1( | |
digestTarget, | |
CryptoJS.enc.Base64.parse(access["accessSecret"]["secret"]) | |
).toString(CryptoJS.enc.Base64); | |
var authorization = "Auth " + access["accessKey"]["key"] + ":" + digest; | |
postman.setEnvironmentVariable('mitter_appAccessKey', access["accessKey"]["key"]); | |
postman.setEnvironmentVariable('mitter_requestDate', dateHeaderValue); | |
postman.setEnvironmentVariable('mitter_requestNonce', nonce); | |
postman.setEnvironmentVariable('mitter_requestPayloadMd5', contentMd5); | |
postman.setEnvironmentVariable('mitter_requestAuthorization', authorization); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment