ldap.js 1.2 KB

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