Linger.Ldap.ActiveDirectory 2.0.0-preview.5

This is a prerelease version of Linger.Ldap.ActiveDirectory.
dotnet add package Linger.Ldap.ActiveDirectory --version 2.0.0-preview.5
                    
NuGet\Install-Package Linger.Ldap.ActiveDirectory -Version 2.0.0-preview.5
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Linger.Ldap.ActiveDirectory" Version="2.0.0-preview.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Linger.Ldap.ActiveDirectory" Version="2.0.0-preview.5" />
                    
Directory.Packages.props
<PackageReference Include="Linger.Ldap.ActiveDirectory" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Linger.Ldap.ActiveDirectory --version 2.0.0-preview.5
                    
#r "nuget: Linger.Ldap.ActiveDirectory, 2.0.0-preview.5"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Linger.Ldap.ActiveDirectory@2.0.0-preview.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Linger.Ldap.ActiveDirectory&version=2.0.0-preview.5&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Linger.Ldap.ActiveDirectory&version=2.0.0-preview.5&prerelease
                    
Install as a Cake Tool

Linger.Ldap.ActiveDirectory

Breaking changes and 2.0 migration notes are documented in the Linger migration guide.

An Active Directory focused LDAP client implementation based on System.DirectoryServices.

Features

  • Active Directory user authentication and validation
  • Synchronous user lookup and search APIs matching the underlying Windows provider
  • OU-scoped search support via searchBase
  • Optional Attributes projection to limit returned fields
  • LDAPS support via LdapConfig.Security
  • Configurable SearchFilter for FindUser and GetUsers
  • Advanced query via IActiveDirectoryClient.SearchUsersByFilter
  • Optional domain controller auto-discovery when LdapConfig.Url is empty
  • Parameterless construction for the current Windows domain
  • Configurable MaxResults limit for each query

Supported Frameworks

  • .NET 10.0
  • .NET 9.0
  • .NET 8.0
  • .NET Standard 2.0

Installation

dotnet add package Linger.Ldap.ActiveDirectory

Quick Start

using Linger.Ldap.ActiveDirectory;
using Linger.Ldap.Contracts;

var config = new LdapConfig
{
    Url = "dc01.example.com",
    Domain = "example",
    SearchBase = "DC=example,DC=com",
    SearchFilter = "(&(objectClass=user)(sAMAccountName={0}))",
    Security = true,
    MaxResults = 1000,
    Credentials = new LdapCredentials
    {
        BindDn = "serviceAccount",
        BindCredentials = "SecurePassword123!"
    },
    Attributes =
    [
        "displayName",
        "sAMAccountName",
        "mail",
        "department",
        "memberOf"
    ]
};

var ldap = new AdLdapClient(config);

For the current Windows domain, configuration is optional:

var ldap = new AdLdapClient();

The parameterless constructor performs no network I/O. It uses the current Windows identity and discovers a domain controller when the first LDAP operation starts.

For dependency injection, register LdapConfig with services.Configure<LdapConfig>(...) and AdLdapClient as the IActiveDirectoryClient implementation. The client consumes IOptions<LdapConfig> directly.

Usage

Validate User Credentials

var (isValid, userInfo) = ldap.ValidateUser("alice", "Password123!");

if (isValid && userInfo is not null)
{
    Console.WriteLine($"DisplayName: {userInfo.DisplayName}");
    Console.WriteLine($"Email: {userInfo.Email}");
}

For the ValidateUser profile check only, set Url to one controller’s actual DNS hostname (e.g. dc01.example.com) or leave it empty for discovery; do not use a domain name, IP, alias or load balancer. The search identity must be able to read the default domain SID, user objectSid and msDS-PrincipalName. On that controller and within the requested OU, the client resolves a unique account, validates its qualified name via ADSI Negotiate, then reads the profile by the original SID and account. Neither identity search follows referrals.

For profile validation a correct password alone is insufficient. An unresolved, ambiguous, unreadable or out-of-scope identity does not authenticate: (false, null). Do not retry via a business lookup to obtain an authenticated profile. Business queries retain their configured filters, wildcard searches and result limits.

For password-only checks use AD IActiveDirectoryCredentialValidator.ValidateCredentials or Novell ILdapCredentialValidator.ValidateCredentialsAsync. Neither requires a pinned controller, Who Am I, or profile read access, and neither checks OU or group membership. For OU restrictions or a verified profile, keep ValidateUser / ValidateUserAsync; never fall back to password-only validation on failure.

LdapConfig.Security defaults to false. AD validates with signed and sealed Negotiate by default. Novell requires explicit Security = true and a trusted LDAPS certificate for all user and service-account password binds. With false it only allows passwordless anonymous queries.

Find a Single User

var user = ldap.FindUser("alice");

if (user is not null)
{
    Console.WriteLine($"SamAccountName: {user.SamAccountName}");
    Console.WriteLine($"DN: {user.Dn}");
}

Search Users

var users = ldap.GetUsers("alice");

foreach (var item in users)
{
    Console.WriteLine($"{item.DisplayName} ({item.Email})");
}

Search in a Specific OU with Custom Bind Credentials

var customCreds = new LdapCredentials
{
    BindDn = "readonly.user",
    BindCredentials = "ReadonlyPassword123!"
};

var usersInOu = ldap.GetUsers(
    "alice",
    ldapCredentials: customCreds,
    searchBase: "OU=Sales,DC=example,DC=com");
IActiveDirectoryClient ldapContract = ldap;

var users = ldapContract.SearchUsersByFilter(
    "(&(objectClass=person)(department=IT)(mail=*))",
    searchBase: "DC=example,DC=com");

Notes

  • This implementation is intended for Windows environments using System.DirectoryServices.
  • In .NET 5+, the implementation is marked with [SupportedOSPlatform("windows")].
  • When Security = true, the client enables AuthenticationTypes.SecureSocketsLayer on the ADSI connection.
  • SearchFilter is used by both FindUser and GetUsers; using {0} placeholder is recommended.
  • SearchUsersByFilter provides raw-filter queries for Active Directory.
  • Blank usernames and raw filters are rejected to prevent accidental full-directory searches.
  • Operations are synchronous because System.DirectoryServices does not provide asynchronous search APIs.
  • If SearchFilter format is invalid, the implementation falls back to a default user filter.
  • Input value in user search is escaped before building LDAP filter to reduce malformed/injection risk.
  • Bind username normalization supports existing domain\\user, UPN (user@domain), and full DN forms.
  • If LdapConfig.Url is empty, Active Directory provider attempts domain controller auto-discovery.
  • The parameterless constructor leaves SearchBase empty and searches from the discovered server root. SearchBase is not inferred; use configured construction to restrict the search scope.
  • MaxResults must be greater than zero and limits each query; the default is 1000.
  • Configuration is snapshotted during client construction. Changes to the original LdapConfig, credentials, or attributes require a new client.
  • Search-operation connection, bind, and directory-server failures throw exceptions. An empty list only means that no users matched.

Key User Properties (LdapUserInfo)

  • DisplayName, SamAccountName, Upn, Dn
  • Email, TelephoneNumber, Mobile, Department, Title
  • Company, Manager, WhenCreated, Status, PwdLastSet
  • MemberOf, ProxyAddresses, OtherTelephone, ProfilePath, HomeDirectory, ExtensionAttribute1

MemberOf, ProxyAddresses, and OtherTelephone preserve LDAP multi-values as string arrays.

Dependencies

  • System.DirectoryServices
  • System.DirectoryServices.AccountManagement
  • Linger.Ldap.Contracts
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed.  net11.0 is compatible. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0-preview.5 44 11/22/2026
2.0.0-preview.4 59 11/14/2026
2.0.0-preview.3 84 9/13/2026
2.0.0-preview.1 70 8/29/2026
1.6.4 159 8/16/2026
1.6.3 148 8/5/2026
1.6.2 146 8/2/2026
1.6.0 130 7/25/2026
1.5.5 135 7/23/2026
1.5.4-preview 121 7/21/2026
1.5.3-preview 125 7/20/2026
1.5.2-preview 118 7/19/2026
1.5.1-preview 123 7/15/2026
1.5.0-preview 121 7/14/2026
1.4.4-preview 129 6/16/2026
1.4.3-preview 122 6/15/2026
1.4.2 136 5/20/2026
1.4.1-preview 130 5/12/2026
1.4.0 138 5/6/2026
1.3.3-preview 122 5/5/2026
Loading failed