Add ldapjs to get user groups upon ldap login

This commit is contained in:
Tuan Dang
2024-04-22 22:02:12 -07:00
parent 62aebe2fd4
commit 2d51445dd9
16 changed files with 394 additions and 110 deletions
@@ -0,0 +1,36 @@
import ldap from "ldapjs";
export const searchGroups = async (
ldapClient: ldap.Client,
filter: string,
base: string
): Promise<{ dn: string; cn: string }[]> => {
return new Promise((resolve, reject) => {
ldapClient.search(
base,
{
filter,
scope: "sub"
},
(err, res) => {
if (err) {
reject(err);
}
const groups: { dn: string; cn: string }[] = [];
res.on("searchEntry", (entry) => {
groups.push({ dn: entry.object.dn, cn: entry.object.cn as string });
});
res.on("error", (error) => {
reject(error);
});
res.on("end", () => {
resolve(groups);
});
}
);
});
};