Is there anyway to implement ldap authentication
in angular2
? I am trying to migrate my web application to Angular2
and I am done with most of the UI part now I left with Authentication
. I have used springboot ldap authentication
in the past app where I connect to my ldaps://example.host:636/
with userDN and password. I am looking for the way to do authentication using ldap. I looked into this link but didn't get where to register or give my ldap
server details to work with, think that is available for paid users. Please suggest me the best way to implement authentication for Angular2 without any other extra cost.
EDITED
Trying to use ldapjs
foud here but getting compilation error ...
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 .....
I have installed ldapjs 1.0.1
my 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"
}
}
}