How to use the ldapjs.createClient function in ldapjs

To help you get started, we’ve selected a few ldapjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github authelia / authelia / src / index.js View on Github external
var config = {
  port: process.env.PORT || 8080,
  ldap_url: yaml_config.ldap.url || 'ldap://127.0.0.1:389',
  ldap_user_search_base: yaml_config.ldap.user_search_base,
  ldap_user_search_filter: yaml_config.ldap.user_search_filter,
  ldap_user: yaml_config.ldap.user,
  ldap_password: yaml_config.ldap.password,
  session_domain: yaml_config.session.domain,
  session_secret: yaml_config.session.secret,
  session_max_age: yaml_config.session.expiration || 3600000, // in ms
  store_directory: yaml_config.store_directory,
  logs_level: yaml_config.logs_level,
  notifier: yaml_config.notifier,
}

var ldap_client = ldap.createClient({
  url: config.ldap_url,
  reconnect: true
});

ldap_client.on('error', function(err) {
  console.error('LDAP Error:', err.message)
})

var deps = {};
deps.u2f = u2f;
deps.nedb = nedb;
deps.nodemailer = nodemailer;
deps.ldap = ldap;
deps.session = session;

server.run(config, ldap_client, deps);
github easy-mock / easy-mock / util / ldap.js View on Github external
return new Promise((resolve, reject) => {
    const dn = opts.credentials.dn
    const passwd = opts.credentials.passwd
    const client = ldap.createClient(opts)

    function onConnect () {
      client.removeListener('error', onError)
      client.bind(dn, passwd, err => {
        /* istanbul ignore if */
        if (err) reject(new Error(err))
        else resolve(client)
      })
    }

    /* istanbul ignore next */
    function onError (err) {
      client.removeListener('connect', onConnect)
      reject(new Error(err))
    }
github nebulade / meemo / src / users.js View on Github external
function profile(identifier, full, callback) {
    assert.strictEqual(typeof identifier, 'string');
    assert.strictEqual(typeof full, 'boolean');
    assert.strictEqual(typeof callback, 'function');

    if (process.env.CLOUDRON_LDAP_URL) {
        var ldapClient = ldapjs.createClient({ url: process.env.CLOUDRON_LDAP_URL });
        ldapClient.on('error', function (error) {
            console.error('LDAP error', error);
        });

        ldapClient.bind(process.env.CLOUDRON_LDAP_BIND_DN, process.env.CLOUDRON_LDAP_BIND_PASSWORD, function (error) {
            if (error) return callback(new UserError(UserError.INTERNAL_ERROR, error));

            ldapClient.search(process.env.CLOUDRON_LDAP_USERS_BASE_DN, { filter: '(|(uid=' + identifier + ')(mail=' + identifier + ')(username=' + identifier + ')(sAMAccountName=' + identifier + '))' }, function (error, result) {
                if (error) return callback(new UserError(UserError.INTERNAL_ERROR, error));

                var items = [];

                result.on('searchEntry', function(entry) {
                    items.push(entry.object);
                });
github grommet / grommet / examples / people-finder / server / ldap.js View on Github external
router.get('/', function(req, res) {
  //console.log('!!! ldap', req.query);

  if (! client) {
    client = ldap.createClient({
      url: req.query.url
    });
  }

  var options = {
    scope: req.query.scope || 'sub',
    filter: req.query.filter,
    attributes: req.query.attributes,
    sizeLimit: req.query.limit || 20
  };

  client.search(req.query.base, options, function (ldapErr, ldapRes) {
    var entries = [];
    if (ldapErr) {
      console.log('client error:', ldapErr);
      if (client) {
github RocketChat / Rocket.Chat / packages / rocketchat-ldap / server / ldap.js View on Github external
}
			});
			tlsOptions.ca = ca;
		}

		if (this.options.encryption === 'ssl') {
			connectionOptions.url = `ldaps://${ connectionOptions.url }`;
			connectionOptions.tlsOptions = tlsOptions;
		} else {
			connectionOptions.url = `ldap://${ connectionOptions.url }`;
		}

		logger.connection.info('Connecting', connectionOptions.url);
		logger.connection.debug('connectionOptions', connectionOptions);

		this.client = ldapjs.createClient(connectionOptions);

		this.bindSync = Meteor.wrapAsync(this.client.bind, this.client);

		this.client.on('error', (error) => {
			logger.connection.error('connection', error);
			if (replied === false) {
				replied = true;
				callback(error, null);
			}
		});

		this.client.on('idle', () => {
			logger.search.info('Idle');
			this.disconnect();
		});
github codingchili / kibana-mithril / src / authentication / ldap.js View on Github external
/**
 * @author Robin Duda
 *
 * Authenticates user+password combinations against an LDAP server.
 */

const LDAP = require('ldapjs');
const Config = require('../config').load('ldap');
const File = require('./file');
const client = LDAP.createClient({url: Config.url});

client.bind(Config.admin.dn, Config.admin.password, err => {
    if (err)
        throw err;
});

function member(id, callback) {
    const search = {
        dn: Config.search["group-dn"],
        options: {
            scope: Config.search.scope,
            filter: new LDAP.filters.AndFilter({
                filters: [
                    new LDAP.filters.EqualityFilter({attribute: 'objectClass', value: 'groupOfNames'}),
                    new LDAP.filters.EqualityFilter({attribute: 'member', value: 'uid=' + id})
                ]
github DataFire / Integrations / integrations / manual / ldap / index.js View on Github external
function getClient(context) {
  var client = ldapJS.createClient({
    url: context.accounts.ldap.host,
  });
  return new Promise((resolve, reject) => {
    client.on('error', err => {
      return reject(err);
    });
    client.bind(context.accounts.ldap.dn, context.accounts.ldap.password, function(err) {
      if (err) return reject(err);
      else resolve(client);
    })
  })
}
github christianvuerings / berkeleydir / legacy / ldapserver.js View on Github external
var express = require('express');
var app = express();

var ldap = require('ldapjs');
var server = 'ldap://ldap.berkeley.edu';
var searchBase = 'ou=people,dc=berkeley,dc=edu';
var client = ldap.createClient({
  url: server
});


var createFilter = function(query) {
  if (!query) {
    query = '*';
  }

  var options = ['displayName', 'mail', 'uid'];
  var filter = '(&(objectclass=*)';

  if (query !== '*') {
    filter += '(|';
    options.forEach(function optionLoop(option) {
        filter += '(' + option + '=*' + query + '*)';
github nebulade / meemo / src / users.js View on Github external
function list(callback) {
    if (process.env.CLOUDRON_LDAP_URL) {
        var client = ldapjs.createClient({ url: process.env.CLOUDRON_LDAP_URL });
        client.bind(process.env.CLOUDRON_LDAP_BIND_DN, process.env.CLOUDRON_LDAP_BIND_PASSWORD, function (error) {
            if (error) return callback(new UserError(UserError.INTERNAL_ERROR, error));

            client.search(process.env.CLOUDRON_LDAP_USERS_BASE_DN, { scope: 'sub' }, function (error, res) {
                if (error) return callback(new UserError(UserError.INTERNAL_ERROR, error));

                var entries = [];
                res.on('searchEntry', function(entry) {
                    var data = {
                        username: entry.object.username,
                        displayName: entry.object.displayname
                    };

                    entries.push(data);
                });
                res.on('error', function (error) {
github naggie / dsdrop / lib / auth / ldap.js View on Github external
exports.login = function(username,password,done) {
	var user_dn = config.ldap_user_dn.replace('{username}',username)

	var client = ldap.createClient({
		//url: 'ldaps://ldapmaster.darksky.io'
		socketPath: '/var/run/slapd/ldapi',
	})

	//client.bind('uid=naggie,ou=users,dc=darksky,dc=io', process.env.BEANS, function (err) {
	client.bind(user_dn, password, function (err) {
		client.unbind()

		if (err && err.message == 'Invalid Credentials')
			done(null,false)
		else
			done(err,!err)
	})
}