Skip to content

Commit

Permalink
Return AD ObjectGuid attribute as buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
eliykat committed Dec 18, 2024
1 parent 6915667 commit b66d97e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/services/ldap-directory.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ import { IDirectoryService } from "./directory.service";

const UserControlAccountDisabled = 2;

/**
* The attribute name for the unique identifier used by Active Directory.
*/
const ActiveDirectoryExternalId = "objectGUID";

export class LdapDirectoryService implements IDirectoryService {
private client: ldapts.Client;
private dirConfig: LdapConfiguration;
Expand Down Expand Up @@ -240,7 +245,7 @@ export class LdapDirectoryService implements IDirectoryService {
* otherwise it falls back to the provided referenceId.
*/
private getExternalId(searchEntry: ldapts.Entry, referenceId: string) {
const attr = this.getAttr<Buffer>(searchEntry, "objectGUID");
const attr = this.getAttr<Buffer>(searchEntry, ActiveDirectoryExternalId);
if (attr != null) {
return this.bufToGuid(attr);
} else {
Expand Down Expand Up @@ -358,6 +363,9 @@ export class LdapDirectoryService implements IDirectoryService {
filter: filter,
scope: "sub",
paged: this.dirConfig.pagedSearch,
// We need to expressly tell ldapts what attributes to return as Buffer objects,
// otherwise they are returned as strings
explicitBufferAttributes: [ActiveDirectoryExternalId],
};
const { searchEntries } = await this.client.search(path, options, controls);
return searchEntries.map((e) => processEntry(e)).filter((e) => e != null);
Expand Down

0 comments on commit b66d97e

Please sign in to comment.