@mntu/nestjs-ldap
v1.0.7
Published
NestJS library to access LDAP
Downloads
278
Readme
NestJS OpenLDAP
Description
A NestJS library for OpenLDAP refer nestjs-ldap
Installation
$ yarn add @mntu/nestjs-ldap
Usage
- Simple:
import { ldapADattributes, LdapModule, Scope } from '@mntu/nestjs-ldap';
@Module({
imports: [
...
LdapModule.registerAsync({
inject: [ConfigService],
useFactory: async (configService: ConfigService) => (
{
logger: new Logger(AppModule.name),
domains: [
LdapModule.createDomainConfig({
name: 'example.com',
url: 'ldaps://localhost:636',
bindDN: 'CN=admin,DC=example,DC=local',
bindCredentials: 'admin',
baseDN: 'DC=example,DC=local',
tlsOptions: { rejectUnauthorized: false },
}),
]
}),
}),
...
]
})
export class AppModule {}
- Simple with Redis cache:
import { ldapADattributes, LdapModule, Scope } from '@mntu/nestjs-ldap';
@Module({
imports: [
...
LdapModule.registerAsync({
inject: [ConfigService],
useFactory: async (configService: ConfigService) => (
{
logger: new Logger(AppModule.name),
cache: new Redis(), /* optional */
cacheUrl: 'redis://username:[email protected]:6379/0', /* optional */
cacheTtl: 600, /* optional */
domains: [
LdapModule.createDomainConfig({
name: 'example.com',
url: 'ldaps://localhost:636',
bindDN: 'CN=admin,DC=example,DC=local',
bindCredentials: 'admin',
baseDN: 'DC=example,DC=local',
tlsOptions: { rejectUnauthorized: false },
}),
]
}),
}),
...
]
})
export class AppModule {}
- Advance:
import { ldapADattributes, LdapModule, Scope } from '@mntu/nestjs-ldap';
@Module({
imports: [
...
LdapModule.registerAsync({
inject: [ConfigService],
useFactory: async (configService: ConfigService) => (
{
logger: new Logger(AppModule.name),
cache: new Redis(), /* optional */
cacheUrl: 'redis://username:[email protected]:6379/0', /* optional */
cacheTtl: 600, /* optional */
domains: [
{
name: 'example.com',
url: 'ldaps://localhost:636',
bindDN: 'CN=admin,DC=example,DC=local',
bindCredentials: 'admin',
searchBase: 'DC=example,DC=local',
searchFilter: '(&(&(|(&(objectClass=user)(objectCategory=person))(&(objectClass=contact)(objectCategory=person)))))',
searchScope: 'sub' as Scope,
groupSearchBase: 'DC=example,DC=local',
groupSearchFilter: '(&(objectClass=group)(member={{dn}}))',
groupSearchScope: 'sub' as Scope,
groupDnProperty: 'dn',
hideSynchronization: false,
searchBaseAllUsers: 'DC=example,DC=local',
searchFilterAllUsers: '(&(&(|(&(objectClass=user)(objectCategory=person))(&(objectClass=contact)(objectCategory=person)))))',
searchFilterAllGroups: 'objectClass=group',
searchScopeAllUsers: 'sub' as Scope,
newObject: 'DC=example,DC=local',
reconnect: true,
groupSearchAttributes: ldapADattributes,
searchAttributes: ldapADattributes,
searchAttributesAllUsers: ldapADattributes,
tlsOptions: { rejectUnauthorized: false },
},
]
}),
}),
...
]
})
export class AppModule {}