Skip to content

Instantly share code, notes, and snippets.

@knjname
Last active June 20, 2019 05:13
Show Gist options
  • Save knjname/0b62867d422ad186d6bea314aa2a2825 to your computer and use it in GitHub Desktop.
Save knjname/0b62867d422ad186d6bea314aa2a2825 to your computer and use it in GitHub Desktop.
const ldap = require("ldapjs");
const server = ldap.createServer();
server.bind("", (req, res, next) => {
console.log(`Bind attempt with ${req.dn.toString()}`);
res.end();
return next();
});
server.search(
"",
(req, res, next) => {
console.log(`Bind attempt with ${req.dn.toString()}`);
return next();
},
(req, res, next) => {
console.log(`In the search with ${req.dn.toString()}`);
res.send({
dn: `CN=user, OU=myorg`,
attributes: {
userPrincipalName: "userPrincipalName",
cn: "userCn",
objectClass: ["user"],
objectCategory: ["user"]
}
});
res.send({
dn: `CN=user2, OU=myorg`,
attributes: {
userPrincipalName: "userPrincipalName",
cn: "userCn",
objectClass: ["user"],
objectCategory: ["user"]
}
});
res.end();
return next();
}
);
server.listen(1389, () => {
console.log(`LDAP started`);
});
{
"scripts": {
"start": "nodemon ldapserver.js"
},
"dependencies": {
"ldapjs": "^1.0.2"
},
"devDependencies": {
"nodemon": "^1.19.1",
"prettier": "^1.18.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment