Last active
April 8, 2021 12:29
-
-
Save emrahtoy/ca1c822653c1f343f3bad5f3801ea0b1 to your computer and use it in GitHub Desktop.
Postman - Quicblox signature pre-request script.
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
function setRequestBody(httpMethod, requestBody) { | |
var timestamp = ~~(Date.now()/1000); // easy way to get required type timestamp | |
var REQUEST = { | |
"application_id":"xxxxxx", // your own application_id | |
"auth_key":"yyyy", // your own auth_key | |
"timestamp":timestamp, | |
"nonce":timestamp, | |
"signature":"" | |
} | |
// i have used QB-Secure global variable so you can too. | |
var SECRET_KEY = pm.globals.get("QB-Secure"); | |
// preparing request/signature data | |
var requestData = ['application_id='+REQUEST.application_id,'auth_key='+REQUEST.auth_key,'nonce='+timestamp,'timestamp='+timestamp].join("&"); | |
// creating signature | |
var hmacDigest = CryptoJS.enc.Hex.stringify(CryptoJS.HmacSHA1(requestData, SECRET_KEY)); | |
REQUEST.signature=hmacDigest; | |
// setting request body as environment so we can use it in our json body via {{QB-RequestBody}} | |
// you can check the first comment, it has screenshot. | |
pm.environment.set('QB-RequestBody',JSON.stringify(REQUEST)); | |
//console out for debug purposes | |
console.log(requestData,REQUEST); | |
} | |
setRequestBody(request['method'], request['data']); |
Author
emrahtoy
commented
Apr 8, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment