无论如何在ldap authentication
中实施angular2
?我正在尝试将我的网络应用程序迁移到Angular2
,现在我完成了大部分用户界面部分,现在我离开了Authentication
。我在过去的应用中使用了springboot ldap authentication
,我使用userDN和密码连接到ldaps://example.host:636/
。我正在寻找使用ldap进行身份验证的方法。我查看了这个link但未找到注册位置或提供我的ldap
服务器详细信息,认为可供付费用户使用。请建议我为Angular2实现身份验证的最佳方法,无需任何其他额外费用。
尝试使用ldapjs
foud here,但收到编译错误...
WARNING in ./~/dtrace-provider/dtrace-provider.js
Module not found: Error: Can't resolve './build' in 'D:\WebStormWork\myapp\node_modules\dtrace-provider'
@ ./~/dtrace-provider/dtrace-provider.js 17:22-81 .....
WARNING in ./~/source-map-support/source-map-support.js
Module not found: Error: Can't resolve 'module' in 'D:\WebStormWork\myapp\node_modules\source-map-support'
@ ./~/source-map-support/source-map-support.js 474:15-32
@ ./~/bunyan/lib/bunyan.js .....
我已安装ldapjs 1.0.1
我的LDAPClientComponent
const ldap = require('ldapjs');
const _ = require('underscore');
@Component({})
export class LdapClientComponent implements OnInit {
username: string = 'my-username';
mypassword: string = 'my-password';
limit: number = 5000;
ngOnInit() { this.auth();}
auth(){
let ldapClient = ldap.createClient('ldap://example.org/'),
search = _.clone(this.ldapConfig.search);
if (search.filter) {
search.filter = search.filter.replace('{{username}}', this.username);
}
ldapClient.search(this.ldapConfig.base, search, function(err, res) {
if (err) { console.log(err); }
else {
res.on('searchEntry', function(entry) {
this.dapCompare(ldapClient, entry.dn);
});
}
});
}
ldapCompare(ldapClient, dn){
ldapClient.compare(dn, 'userPassword', this.mypassword, function(err, pass ) {
if (err) {console.log(err);}
else if (!pass) {
console.log('Not Authorized');
} else {
console.log('OK!');
}
});
}
ldapConfig = {
"server": {
"url": "ldap://example.org/"
},
"base": "dc=example,dc=org",
"search": {
"filter": "(uid={{username}})",
"scope": "sub"
}
}
}