node-activedirectory icon indicating copy to clipboard operation
node-activedirectory copied to clipboard

Users profile picture

Open swrocket opened this issue 7 years ago • 4 comments

Is there a way to request additional fields for findUser? I would like to get the users profile picture from AD.

TIA,

Andrew

swrocket avatar Apr 02 '17 14:04 swrocket

Hello,

I recently did just this. Here is my code:

config={baseDN:baseDN, url: url, username, password, attributes:{ user: [ 'dn', 'distinguishedName', 'userPrincipalName', 'sAMAccountName', 'mail', 'lockoutTime', 'whenCreated', 'pwdLastSet', 'userAccountControl', 'employeeID', 'sn', 'givenName', 'initials', 'cn', 'displayName', 'comment', 'description', 'thumbnailPhoto' ], }, entryParser:customParser}

Custom parser is the following function:

const customParser=function(entry, raw, callback){ if (raw.hasOwnProperty("thumbnailPhoto")){ entry.thumbnailPhoto = raw.thumbnailPhoto; } callback(entry) }

danielhstahl avatar Apr 26 '17 19:04 danielhstahl

Hello,

Thanks for this preview answer but i want to know how to display that because when you got it. In my case i tried to get that but i couldn't display it because it is an objet (a Buffer)

Thanks.

capture

hdev11 avatar May 12 '17 14:05 hdev11

The data schould be a byte array, you might have to transform it to base64. That schould give you the image source in a more usable form.

audhen avatar Jun 29 '17 11:06 audhen

@swrocket Hope this helps!

var userPic = new Buffer(user["thumbnailPhoto"]).toString('base64');

Now the userPic would be the base 64 encoded image, you can send this to front end and display the image using img tag

you could refer to http://jsfiddle.net/hpP45/

jithurjacob avatar Jul 06 '17 05:07 jithurjacob