1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- /* global WIKI */
- // ------------------------------------
- // LDAP Account
- // ------------------------------------
- const LdapStrategy = require('passport-ldapauth').Strategy
- const fs = require('fs')
- module.exports = {
- key: 'ldap',
- title: 'LDAP / Active Directory',
- useForm: true,
- props: ['url', 'bindDn', 'bindCredentials', 'searchBase', 'searchFilter', 'tlsEnabled', 'tlsCertPath'],
- init (passport, conf) {
- passport.use('ldapauth',
- new LdapStrategy({
- server: {
- url: conf.url,
- bindDn: conf.bindDn,
- bindCredentials: conf.bindCredentials,
- searchBase: conf.searchBase,
- searchFilter: conf.searchFilter,
- searchAttributes: ['displayName', 'name', 'cn', 'mail'],
- tlsOptions: (conf.tlsEnabled) ? {
- ca: [
- fs.readFileSync(conf.tlsCertPath)
- ]
- } : {}
- },
- usernameField: 'email',
- passReqToCallback: false
- }, (profile, cb) => {
- profile.provider = 'ldap'
- profile.id = profile.dn
- WIKI.db.User.processProfile(profile).then((user) => {
- return cb(null, user) || true
- }).catch((err) => {
- return cb(err, null) || true
- })
- }
- ))
- }
- }
|