CaseTunisia.Tools.Ldap 1.2.1
CaseTunisia.Tools.Ldap
This library is a wrapper around Novell.Directory.Ldap.NETStandard that authenticate and return the logged in user roles.
First add LdapConfiguration to you appsettings.json:
"LdapConfiguration": {
"Url": "172.168.1.3",
"Port": 389,
"SSL": true,
"CertificatePath": "PATH_TO_CERT_FILE"
"SearchBase": "OU=CASE Tunisia,DC=CASE-Tunisia,DC=internal",
"SearchFilter": "(&(objectClass=user)(objectClass=person)(sAMAccountName={0}))",
}
- Initialize LdapConfiguration which is used to preconfigure LdapService
services.Configure<LdapConfiguration>(Configuration.GetSection("LdapConfiguration"));
- Add LdapService to your midlewares:
services.AddSingleton<ILdapService, LdapService>();
- Inject the service where you want to use it
demo code
LdapConfiguration ldapConfiguration = new()
{
Url = "172.168.1.3",
Port = 389,
SearchBase = "OU=CASE Tunisia,DC=CASE-Tunisia,DC=internal",
SearchFilter = "(&(objectClass=user)(objectClass=person)(sAMAccountName={0}))",
UserName = $"case-tunisia\\git.user",
Password = "case123",
};
...
LdapService _ldapService = new LdapService(ldapConfiguration);
_ldapService.Authenticate();
var user = _ldapService.GetUser($"case-tunisia\\a.habbachi");
List<string> roles = _ldapService.GetUserRoles(user);
No packages depend on CaseTunisia.Tools.Ldap.
.NET Standard 2.1
- Microsoft.Extensions.Options (>= 6.0.0)
- Novell.Directory.Ldap.NETStandard (>= 3.6.0)
- Portable.BouncyCastle (>= 1.9.0)