I first want to mention that I'm not an expert with LDAP.
What I need is to get from my company's ldap some information including the user photo.
My problem is that after I get all the information I need, the thumbnailPhoto
appears to be somehow corrupted. I'll show an example:
\ufffdPNG\r\n\u001a\n\u0000\u0000\u0000\rIHDR\u0000\u0000\u0000\ufffd\u0000\u0000\u0000\u ...
I first noticed this when I tried to apply it on my front end client and couldn't make an image from the returning Buffer. Plus when I checked in LDAP to see the photo size of the returned one is almost double in size.
I checked to see if there was a problem with way the photo was saved in LDAP, copy pasted into a converter and all was fine.
I'll give a code snippet of how I get info from LDAP with a library called activedirectory:
const ActiveDirectory = require('activedirectory');
exports = module.exports = () => {
return {
auth: (doc) => {
let user = 'project@ad.company.com',
passwd = 'password provided by IT team';
return new Promise((resolve, reject) => {
let ad = new ActiveDirectory({
url: 'ldap://something.ad.company.com:389',
baseDN: 'OU=Company,DC=ad,DC=company,DC=com',
username: user,
password: passwd,
attributes: { user: [] }
});
ad.authenticate(doc.username, doc.password, (err, auth) => {
if(auth){
ad.findUser(doc.username, (err, user) => {
if(err){
reject(err);
} else {
resolve(user);
}
})
} else {
reject(err);
}
});
});
}
}
}
exports['@singleton'] = true;
I've been struggling with this for some time but I don't understand what happens. The only information I have about this is at this link which tells that "ldapjs does not know that the thumbnail is really binary" but that was in 2013.
I would appreciate some help, or at least any other methods or libraries I can use in node with express.
At the moment the application uses:
"activedirectory": "^0.7.2",
"electrolyte": "0.3.0",
"express": "^4.16.3",
Thanks in advance.
After reviewing again all the issues posted on activedirectory repository I found the answer I needed.
const customeParser = function(entry, raw, callback){ if (raw.hasOwnProperty("thumbnailPhoto")){ entry.thumbnailPhoto = raw.thumbnailPhoto; } callback(entry) }
let ad = new ActiveDirectory({
url: 'ldap://something.ad.company.com:389',
baseDN: 'OU=Company,DC=ad,DC=company,DC=com',
username: user,
password: passwd,
attributes: { user: [] },
entryParser: customeParser
});
On the front end and if you are using Angular 4+:
this.domSanitizer.bypassSecurityTrustUrl('data:image/png;base64,'+ new Buffer(thumbnailPhoto).toString('base64'))