duo_nodejs
duo_nodejs copied to clipboard
signing requests for the admin api
I don't know if this library is a good place for this, but here is the code to sign a request for the Admin API as explained here:
var moment = require('moment');
var crypto = require('crypto');
var qs = require('querystring');
module.exports = function (method, host, path, params, skey, ikey) {
var now = moment.utc().format('ddd, D MMM YYYY H:mm:ss ') + '-0000';
var canon = [ now,
method.toUpperCase(),
host.toLowerCase(),
path,
qs.stringify(params) ].join('\n');
var hmac = crypto.createHmac('sha1', skey)
.update(canon)
.digest('hex');
var auth = new Buffer([ikey, hmac].join(':')).toString('base64');
return {
'Date': now,
'Authorization': 'Basic ' + auth
};
};
Thanks, José. We'll take a look and get back to you.
Hi, José. I started a new github project for the API client library here: https://github.com/duosecurity/duo_api_nodejs
I added some unit tests, code for various corner cases that occur when escaping special characters, and an example. Thanks for getting the ball rolling!
Hi @ben-duo glad to hear that :)