1

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"
        }
    }
}
Community
  • 1
  • 1
user1653027
  • 789
  • 1
  • 16
  • 38
  • For best results, post the code you have written that is not working, to allow someone to help direct you to the solution, as opposed to asking someone to do it for you. – Steven Scott Feb 22 '17 at 23:33
  • @StevenScott, sorry I am not asking to do it for me, I am asking for guidance as I have no clue to from where to start, I tried with above mentioned link but the ldap connection is not available for free version. so want to know if there is any way to do it. I am trying with different approach not with `Autho` though. – user1653027 Feb 23 '17 at 06:40

0 Answers0