1

无论如何要实施ldap authenticationangular2?我正在尝试将我的 Web 应用程序迁移到Angular2,现在我已经完成了大部分 UI 部分Authentication。我springboot ldap authentication在过去的应用程序中使用过我ldaps://example.host:636/使用 userDN 和密码连接到我的应用程序。我正在寻找使用 ldap 进行身份验证的方法。我查看了此链接,但没有找到在哪里注册或提供我的ldap服务器详细信息以供使用,认为付费用户可以使用。请建议我为 Angular2 实施身份验证的最佳方法,无需任何其他额外费用。

已编辑

尝试在这里ldapjs使用foud但出现编译错误...

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"
        }
    }
}
4

0 回答 0