vesse / node-ldapauth-fork

Simple node.js module to authenticate against an LDAP server
Other
127 stars 79 forks source link

jpegPhoto decoding #63

Closed mattiaa95 closed 6 years ago

mattiaa95 commented 6 years ago

when the user object shows up I am trying to save the jpegPhoto to a file for use as the profile pic. But I cannot figure out the format

I have tried (among many other things): fs.writeFileSync(jpgPath, ldapUser.jpegPhoto);

And

var jpg = new Buffer(ldapUser.jpegPhoto, 'base64');
fs.writeFileSync(jpgPath, jpg);

And

  var img64 = Buffer.from(user.jpegPhoto).toString('base64');
  var foto = "<div><img src='data:image/jpeg;base64,"+img64+"'/></div>"
            fs.appendFile('index.html', foto, function (err) {
              if (err) throw err;
              console.log('Saved!');
            });

Thanks!

vesse commented 6 years ago

I have no idea about the format. However there is an option that is likely helpful. From the readme:

includeRaw - Optional, default false. Set to true to add property _raw containing the original buffers to the returned user object. Useful when you need to handle binary attributes

ldapjs return object is an UTF-8 representation and likely you cannot get the binaries working with that, but they should work with raw buffers.

mattiaa95 commented 6 years ago

Thank you very much for your reply.How do I access the _raw property of the user who returns the ldap? Like this.: ldapUser._raw.jpegPhoto

vesse commented 6 years ago

Yes, it appears as user._raw