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.

46 lines
1.2 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 = {
  9. key: 'ldap',
  10. title: 'LDAP / Active Directory',
  11. useForm: true,
  12. props: ['url', 'bindDn', 'bindCredentials', 'searchBase', 'searchFilter', 'tlsEnabled', 'tlsCertPath'],
  13. init (passport, conf) {
  14. passport.use('ldapauth',
  15. new LdapStrategy({
  16. server: {
  17. url: conf.url,
  18. bindDn: conf.bindDn,
  19. bindCredentials: conf.bindCredentials,
  20. searchBase: conf.searchBase,
  21. searchFilter: conf.searchFilter,
  22. searchAttributes: ['displayName', 'name', 'cn', 'mail'],
  23. tlsOptions: (conf.tlsEnabled) ? {
  24. ca: [
  25. fs.readFileSync(conf.tlsCertPath)
  26. ]
  27. } : {}
  28. },
  29. usernameField: 'email',
  30. passReqToCallback: false
  31. }, (profile, cb) => {
  32. profile.provider = 'ldap'
  33. profile.id = profile.dn
  34. wiki.db.User.processProfile(profile).then((user) => {
  35. return cb(null, user) || true
  36. }).catch((err) => {
  37. return cb(err, null) || true
  38. })
  39. }
  40. ))
  41. }
  42. }