2
0

authentication.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* global WIKI */
  2. // ------------------------------------
  3. // LDAP Account
  4. // ------------------------------------
  5. const LdapStrategy = require('passport-ldapauth').Strategy
  6. const fs = require('fs')
  7. module.exports = {
  8. init (passport, conf) {
  9. passport.use('ldapauth',
  10. new LdapStrategy({
  11. server: {
  12. url: conf.url,
  13. bindDn: conf.bindDn,
  14. bindCredentials: conf.bindCredentials,
  15. searchBase: conf.searchBase,
  16. searchFilter: conf.searchFilter,
  17. searchAttributes: ['displayName', 'name', 'cn', 'mail'],
  18. tlsOptions: (conf.tlsEnabled) ? {
  19. ca: [
  20. fs.readFileSync(conf.tlsCertPath)
  21. ]
  22. } : {}
  23. },
  24. usernameField: 'email',
  25. passReqToCallback: false
  26. }, (profile, cb) => {
  27. profile.provider = 'ldap'
  28. profile.id = profile.dn
  29. WIKI.models.users.processProfile(profile).then((user) => {
  30. return cb(null, user) || true
  31. }).catch((err) => {
  32. return cb(err, null) || true
  33. })
  34. }
  35. ))
  36. }
  37. }