我正在为我的团队使用 MEAN 堆栈(MongoDB、Express、Angular 和 Node)创建的网站设置 LDAP 身份验证。但是,我的绑定(bind)不成功。
这项工作已在 Windows 10 上完成。我在执行 ldap.js documentation 时遇到问题用于客户端集成,但已找到Github issue这看起来很有希望。我相信我的问题出在绑定(bind) API 上。我的理解是,我需要在服务器中给它一些东西(我使用我的mailNickname,尽管我也尝试过我的userPrincipalName)和一些私有(private)的东西(我的密码)。我使用 AD Explorer,它允许我使用我的 userPrincipalName (first.last@company.com) 和密码连接到公司服务器。我能够使用 mailNickname 和 userPrincipalName 等多个属性在服务器中搜索自己,因此我不确定是什么导致了我的绑定(bind)错误。
今年夏天早些时候,我们在为 Hygieia 仪表板建立身份验证时使用了相同的服务器(带有 Active Directory),并且 AD Explorer 运行良好,因此我确信我拥有正确的服务器。
var ldap = require('ldapjs');
var assert = require('assert');
// Create client and bind to AD
var ldapClient = ldap.createClient({
url: "ldap://servername.us.company.com:389"
});
ldapClient.bind(myDN, password, function(err) {
assert.ifError(err);
});
var opts = {
scope: 'sub',
filter: '(mailNickname=NICKNAME4Testing)'
};
ldapClient.search('OU=AllUsers,DC=us,DC=company,DC=com', opts, function(err, res) {
assert.ifError(err);
res.on('searchEntry', function(entry) {
console.log(entry.object.name);
console.log(entry.object.dn);
});
res.on('searchReference', function(referral) {
console.log('referral: ' + referral.uris.join());
});
res.on('error', function(err) {
console.error('error: ' + err.message);
});
res.on('end', function(result) {
console.log(result);
});
});
当我从命令行运行 npm start 时,我期望终端上的输出为四行,告诉我我的名字、我的 DN、搜索引用和“结束”。然而,我实际得到的是
AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 80090308: >LdapErr: DSID-0C09042F, comment: AcceptSecurityContext error, data 52e, >v2580
根据another page that I found ,问题可能出在我的密码上,但我使用的正是通过 ADExplorer 访问我的计算机和服务器所用的密码。 有一个特殊字符,但我尝试同时使用 CHARACTER 和\CHARACTER 但无济于事。
最佳答案
好吧,我不断挖掘并设法解决这个特定错误。我使用了 userPrincipalName,而不是我的 DN,然后保持密码不变。我不再有错误,但现在我有一个 SearchResponse,我不太确定如何处理。
关于javascript - 如何与公司 LDAP 服务器成功绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57060230/