https://www.jianshu.com/p/50a214f51dd1javascript
LDAP 是轻量级目录访问协议的简称(Lightweight Directory Access Protocol).用于访问目录服务。它是 X.500 目录访问协议的移植,可是简化了实现方法。html
含有目录数据库,提供给用户查询、使用信息的计算机就是目录服务器。X.500是一套目录服务标准,定义了一个机构在全局范围内共享名称和与名称相关联的数据。X.500采用层次结构,其中的管理域能够提供这些域内的用户和资源信息,并定义了强大的搜索功能,所以查询变得更简单。因为X.500目录服务协议过于复杂,所以开发了LDAP(轻量级的目录访问协议)。LDAP目录存储和组织的基本数据结构称为条目,每一个条目都有惟一的标识符,并有一些属性,就相似数据库中每一行表明一条数据,而且有一项是惟一标识。可是LDAP比数据库简单不少,而且经常使用于查询(也就是读取),写操做不常使用。![]()
上图是一个典型的目录结构
第一个节点 DN 命名为:dn:dc=example,dc=com
第二个节点 DN 命名为:dn:ou=People,dc=example,dc=com
第三个节点 DN 命名为:dn:uid=bjensen,ou=people,dc=example,dc=com
https://www.npmjs.com/package/ldapjsjava
LDAPjs makes the LDAP protocol a first class citizen in Node.js.node
For full docs, head on over to http://ldapjs.org.git
var ldap =var server = ldapserverserverTo run that, assuming you've got the OpenLDAP client on your system:github
https://www.ibm.com/developerworks/cn/opensource/se-use-ldap-authentication-authorization-node.js-bluemix-application/index.html数据库
- 使用用户的 DN,您可尝试使用该用户密码绑定到服务器。
12345// When you have the DN, try to bind with it to check the password
var userClient = ldap.createClient({
url: sessionData.ldap.url
});
userClient.bind(sessionData.dn, sessionData.passwd, function(err) {
- 若是绑定成功,则意味着用户信息是正确的,您能够开始新会话。若是绑定失败,则密码是错误的(该 uid 已被用,不然该流程将在子步骤 4 中失败)。
12345678if (err == null) {
var sessionID = logon(sessionData);
res.setHeader("Set-Cookie", ["sessionID=" + sessionID]);
res.redirect("main.html");
} else
res.send("You are not " + sessionData.uid);
});
源码:npm
https://github.com/qbzzt/bluemix/tree/master/security/201802/login-using-ldap服务器
app.post("/ad", (req, res) => { var client = ldap.createClient({ url: req.body.serverUrl }); client.bind(req.body.username + '@' + req.body.domain, req.body.password, function(err) { if (err) { res.send("Bind failed " + err); return; } res.send("Log on successful"); }); // client.bind }); // app.post("/ad...")