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.

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