@@ -18,6 +18,11 @@ import { IDirectoryService } from "./directory.service";
18
18
19
19
const UserControlAccountDisabled = 2 ;
20
20
21
+ /**
22
+ * The attribute name for the unique identifier used by Active Directory.
23
+ */
24
+ const ActiveDirectoryExternalId = "objectGUID" ;
25
+
21
26
export class LdapDirectoryService implements IDirectoryService {
22
27
private client : ldapts . Client ;
23
28
private dirConfig : LdapConfiguration ;
@@ -240,7 +245,7 @@ export class LdapDirectoryService implements IDirectoryService {
240
245
* otherwise it falls back to the provided referenceId.
241
246
*/
242
247
private getExternalId ( searchEntry : ldapts . Entry , referenceId : string ) {
243
- const attr = this . getAttr < Buffer > ( searchEntry , "objectGUID" ) ;
248
+ const attr = this . getAttr < Buffer > ( searchEntry , ActiveDirectoryExternalId ) ;
244
249
if ( attr != null ) {
245
250
return this . bufToGuid ( attr ) ;
246
251
} else {
@@ -358,6 +363,9 @@ export class LdapDirectoryService implements IDirectoryService {
358
363
filter : filter ,
359
364
scope : "sub" ,
360
365
paged : this . dirConfig . pagedSearch ,
366
+ // We need to expressly tell ldapts what attributes to return as Buffer objects,
367
+ // otherwise they are returned as strings
368
+ explicitBufferAttributes : [ ActiveDirectoryExternalId ] ,
361
369
} ;
362
370
const { searchEntries } = await this . client . search ( path , options , controls ) ;
363
371
return searchEntries . map ( ( e ) => processEntry ( e ) ) . filter ( ( e ) => e != null ) ;
0 commit comments