Skip to content

Instantly share code, notes, and snippets.

@mindnuts
Last active May 17, 2017 13:02
Show Gist options
  • Save mindnuts/663868edfdf1e8971b4708ebc9887d52 to your computer and use it in GitHub Desktop.
Save mindnuts/663868edfdf1e8971b4708ebc9887d52 to your computer and use it in GitHub Desktop.
Reed.co.uk API request Signature in NodeJS (https://www.reed.co.uk/developers/Recruiter#setting-Security), Tested with Node v6.9.2
/*
Inspired from the Perl example on the API documentation page
*/
const crypto = require('crypto');
const _ = require('lodash');
const api_key = '7e94901a-f6a2-4b97-a1df-0bafdeba3b99';
const character_array = api_key.split('');
const new_array = _.pullAt(character_array, [6,7,4,5,2,3,0,1,11,12,9,10,16,17,14,15,19,20,21,22,24,25,26,27,28,29,30,31,32,33,34,35]);
var hex_string = '';
for (var i = 0; i < new_array.length; i = i +2) {
hex_string += new_array[i] + new_array[i+1];
}
const buf = new Buffer(hex_string, 'hex');
const hmac = crypto.createHmac('SHA1', buf);
hmac.on('readable', () => {
const data = hmac.read();
if (data)
console.log(data.toString('base64'));
// Prints:
// devB9o3OAKaHUuE4Ln6lLQ2GQ2I=
});
hmac.write('POSTReedAgenthttps://www.reed.co.uk/recruiter/api/1.0/jobswww.reed.co.uk2017-05-15T10:59:37.8525821+01:00');
hmac.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment