@mntu/nestjs-ldap
TypeScript icon, indicating that this package has built-in type declarations

1.0.7 • Public • Published

NestJS OpenLDAP

Nest Logo Openldap Logo

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:password@redis-example.com: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:password@redis-example.com: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 {}

Bonus

Package Sidebar

Install

npm i @mntu/nestjs-ldap

Weekly Downloads

78

Version

1.0.7

License

MIT

Unpacked Size

324 kB

Total Files

57

Last publish

Collaborators

  • mntu