Press "Enter" to skip to content

NODEJS连ldap认证

使用ldap-authentication库https://www.npmjs.com/package/ldap-authentication

官方样例代码:

let authenticated = await authenticate({
  ldapOpts: { url: 'ldap://ldap.forumsys.com' },
  userDn: 'uid=gauss,dc=example,dc=com',
  userPassword: 'password',
  userSearchBase: 'dc=example,dc=com',
  usernameAttribute: 'uid',
  username: 'gauss',
})

我实际操作连我们单位ldap域的代码:

const { authenticate } = require('ldap-authentication');

    let authenticated = await authenticate({
      ldapOpts: { url: 'ldaps://ldap.xiaocaicai.com', tlsOptions: { rejectUnauthorized: false } },
      userDn: 'username@xx.com',
      userPassword: 'thepassword',
      userSearchBase: 'DC=xiaocaicai,DC=com',
      usernameAttribute: 'sAMAccountName',
      username: 'username',
    });
    console.log(JSON.stringify(authenticated));

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注