I'm trying to get information from AD using node.js. I've tried activedirectory
and ldapauth-fork
and in general the code works, but if I need some octetstring
data like objectGUID
, I see a rubbish string in the object. I found that binary data is converted into a string as utf-8. But the problem is that the data is damaged during convertion (a lot of cahrs with 65533 code) and I can't revert the string to original binary.
How can I access data in octetstring
format to get correct binary representation?
const ActiveDirectory = require('activedirectory');
const config = {
url: 'LDAP://ldap.example.com',
baseDN: 'OU=Users,DC=example,DC=com',
username: 'user@example.com',
password: 'password'
};
const ad = new ActiveDirectory(config);
const query = {
filter: '(objectClass=user)',
attributes: ["dn", "cn", "objectGUID", "objectSid"]
};
ad.findUsers(query, function (err, result) {
if (err) {
return console.error(err);
}
console.log(result.length);
console.log(result[0]); // objectGUID contains rubbish
console.log([...result[0].objectGUID].map(ch => ch.charCodeAt(0)));
});
Related: