duo_nodejs icon indicating copy to clipboard operation
duo_nodejs copied to clipboard

signing requests for the admin api

Open jfromaniello opened this issue 12 years ago • 3 comments

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
  };
};

jfromaniello avatar Apr 12 '14 22:04 jfromaniello

Thanks, José. We'll take a look and get back to you.

briankelly avatar Apr 12 '14 22:04 briankelly

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!

ben-duo avatar Apr 18 '14 15:04 ben-duo

Hi @ben-duo glad to hear that :)

jfromaniello avatar Apr 18 '14 16:04 jfromaniello