Evo.Auth/apps/api/src/ldap/ldap.service.ts
2022-11-23 17:06:34 +03:00

27 lines
784 B
TypeScript

import { Injectable } from '@nestjs/common';
import type { AuthenticationOptions } from 'ldap-authentication';
import { authenticate } from 'ldap-authentication';
import type { LdapUser } from './types/user';
@Injectable()
export class LdapService {
async authenticate(login: string, password?: string) {
const options: AuthenticationOptions = {
ldapOpts: {
url: process.env.ldapUrl,
},
adminDn: process.env.bindDN,
adminPassword: process.env.bindCredentials,
userSearchBase: process.env.base,
usernameAttribute: process.env.attribute,
username: login,
userPassword: password,
verifyUserExists: password === undefined,
};
const ldapUser: LdapUser = await authenticate(options);
return ldapUser;
}
}