You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.0 KiB

  1. 'use strict'
  2. /* global wiki */
  3. // ------------------------------------
  4. // LDAP Account
  5. // ------------------------------------
  6. const LdapStrategy = require('passport-ldapauth').Strategy
  7. const fs = require('fs')
  8. module.exports = (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.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. }