当我尝试使用 ldapjs 创建新的 AD 用户时出现 InvalidDnSyntaxError

问题描述 投票:0回答:1

我正在尝试通过 ldapjs 创建用户,这是我的代码:

async onboardUser(targetUser, ou) {
        targetUser.distinguishedName = `cn=${user.username}, ${ou}`;

        return new Promise(function (resolve, reject) {
            const entry = {
                distinguishedName: targetUser.distinguishedName,
                displayName: targetUser.displayName,
                sAMAccountName: targetUser.username, 
                cn: targetUser.displayName,
                name: targetUser.displayName,
                sn: targetUser.lname,
                givenName: targetUser.fname,
                userPrincipalName: targetUser.email, 
                mail: targetUser.email,
                co: targetUser.country,
                company: targetUser.company,
                manager: targetUser.manager['distinguishedName'],
                physicalDeliveryOfficeName: targetUser.city,
                department: targetUser.department,
                title: targetUser.title,
                unicodePwd: Buffer.from('"' + targetUser.password + '"', 'utf16le').toString(),
                objectclass: 'user',
                userAccountControl: 512, //NORMAL_ACCOUNT
            };

            // Create user in AD, error occurs here
            ldapjs.add(targetUser.distinguishedName, entry, (err) => {
                if (err) {
                    logger.error(err.stack);
                    reject(err);
                } else {
                    resolve('success');
                }
            });
        });
    }

但是,我收到以下错误:

InvalidDnSyntaxError: 00002081: NameErr: DSID-03050F42, problem 2003 (BAD_ATT_SYNTAX), data 0, best match of:
    'cn=awesomeusername, ou=Users, ou=Accounts, dc=company, dc=org'

我陷入了上述错误,不知道如何继续。非常欢迎任何关于我可能做错的事情的建议。

感谢您的时间和关注🙏

javascript node.js active-directory ldap ldapjs
1个回答
0
投票

尝试去掉逗号后面的空格:

targetUser.distinguishedName = `cn=${user.username}, ${ou}`;
//                                                  ^

请参阅 MS 文档: https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ldap/distinguished-names

看起来应该是:'cn=awesomeusername,ou=Users,ou=Accounts,dc=company,dc=org'

© www.soinside.com 2019 - 2024. All rights reserved.