cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
238
Views
0
Helpful
0
Replies

Postman preprocessing script to connect with Duo

Apoorva_Anne
Level 1
Level 1

Hi, Can someone help me with this postman preprocessing script.

This is the script I am using to connect with DUO

function getAuthHeader(httpMethod, requestUrl, requestBody) { console.log(requestBody); //body data console.log(httpMethod); // http type: POST, GET, ETC
var CLIENT_KEY = ‘XXXX’;
var SECRET_KEY = ‘XXXX’;
//var AUTH_TYPE = ‘HMAC-SHA1’;
var moment = require(‘moment’)
//const moment= require(‘moment’);
/* Uncomment out lines below to use your test for getting correct formatted time and date */
var timestamp = moment().format(‘ddd, DD MMM YYYY HH:mm:ss ZZ’);
//var timestamp1 = moment().utcOffset(‘timestamp’);
//var timestamp1 = timestamp.toUTCString();
pm.environment.set(“timestampHeader”,timestamp);
//var timestamp = “Mon, 24 Apr 2023 16:38:18 -0600” ;
//pm.environment.set(“timestampHeader”,timestamp);
var hostname = “■■■■■■■■■■■■■■■■■■■■■■■■■■”;
var apicall = ‘/admin/v1/users’
var method = ‘POST’
var body = ‘username=XXXXX’ //sample username
var requestData = timestamp +‘\n’+method+‘\n’+ hostname +‘\n’+ apicall +‘\n’+ body;
//requestData = requestData.normalize([‘NFC’]);
console.log(requestData);
var hmacDigest = CryptoJS.HmacSHA1(requestData, SECRET_KEY);
console.log(“hmacDigest”);

var prebase = CLIENT_KEY+“:”+hmacDigest;
console.log(prebase);
var baseComplete = btoa(prebase);
console.log(baseComplete);
var authHeader = "Basic "+baseComplete;
return authHeader;
}
postman.setEnvironmentVariable(‘hmacAuthHeader’, getAuthHeader(request[‘method’], request[‘url’], request[‘data’]));

Headers passing :

Authorization - {{hmacAuthHeader}}
Date - {{timestampHeader}}
Content-Type - application/x-www-form-urlencoded

But seeing an error

“code”: 40103,
“message”: “Invalid signature in request credentials”,
“stat”: “FAIL”

I have seen many posts on this preprocessing script, but no one is clear on how they made it working.

Please suggest what is wrong is the script and how to convert the time to UTC .

0 Replies 0
Quick Links