Linger.Ldap.Contracts 0.7.2

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Linger.Ldap.Contracts --version 0.7.2
                    
NuGet\Install-Package Linger.Ldap.Contracts -Version 0.7.2
                    
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.Contracts" Version="0.7.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Linger.Ldap.Contracts" Version="0.7.2" />
                    
Directory.Packages.props
<PackageReference Include="Linger.Ldap.Contracts" />
                    
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.Contracts --version 0.7.2
                    
#r "nuget: Linger.Ldap.Contracts, 0.7.2"
                    
#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.Contracts@0.7.2
                    
#: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.Contracts&version=0.7.2
                    
Install as a Cake Addin
#tool nuget:?package=Linger.Ldap.Contracts&version=0.7.2
                    
Install as a Cake Tool

Linger.Ldap.Contracts

📝 View this document in: English | 中文

A C# LDAP contract library that provides standardized interfaces and models for integrating LDAP directory services across multiple .NET platforms.

Introduction

Linger.Ldap.Contracts provides a set of standardized LDAP operation interfaces and models, making it easier to implement consistent LDAP functionality across different .NET applications.

Features

Core Contracts

  • Standardized LDAP operation interfaces
  • Common LDAP attribute definitions
  • Cross-platform compatible models
  • Type-safe LDAP operations

Model Support

  • Comprehensive user attribute mappings
  • Groups and organizational unit models
  • Search filter definitions
  • Connection parameter contracts

ASP.NET Core Integration

Configuring Services

In ASP.NET Core projects, you can utilize LDAP services through dependency injection:

// 在Program.cs或Startup.cs中配置服务
public void ConfigureServices(IServiceCollection services)
{
    // 添加LDAP配置
    services.Configure<LdapConfig>(Configuration.GetSection("LdapConfig"));
    
    // 根据具体实现注册LDAP服务
    // 针对Active Directory
    services.AddScoped<ILdap, Linger.Ldap.ActiveDirectory.Ldap>();
    
    // 或者针对Novell LDAP
    // services.AddScoped<ILdap, Linger.Ldap.Novell.Ldap>();
}

appsettings.json配置示例

{
  "LdapConfig": {
    "Url": "ldap.example.com",
    "Domain": "example",
    "SearchBase": "DC=example,DC=com",
    "SearchFilter": "(&(objectClass=user)(|(sAMAccountName={0})(userPrincipalName={0})(mail={0})))",
    "Security": true,
    "Credentials": {
      "BindDn": "serviceaccount",
      "BindCredentials": "password"
    },
    "Attributes": [
      "displayName", "mail", "sAMAccountName", "userPrincipalName", 
      "telephoneNumber", "department", "title", "givenName", "sn"
    ]
  }
}

使用示例

用户身份验证
public class AuthenticationService
{
    private readonly ILdap _ldap;
    
    public AuthenticationService(ILdap ldap)
    {
        _ldap = ldap;
    }
    
    public async Task<bool> AuthenticateUserAsync(string username, string password)
    {
        var (isValid, userInfo) = await _ldap.ValidateUserAsync(username, password);
        
        if (isValid && userInfo != null)
        {
            // 用户认证成功,可以使用userInfo中的信息
            Console.WriteLine($"用户 {userInfo.DisplayName} 认证成功");
            return true;
        }
        
        return false;
    }
}
查找用户信息
public class UserService
{
    private readonly ILdap _ldap;
    
    public UserService(ILdap ldap)
    {
        _ldap = ldap;
    }
    
    public async Task<AdUserInfo?> GetUserInfoAsync(string username)
    {
        return await _ldap.FindUserAsync(username);
    }
    
    public async Task<IEnumerable<AdUserInfo>> SearchUsersAsync(string searchTerm)
    {
        return await _ldap.GetUsersAsync(searchTerm);
    }
    
    public async Task<bool> CheckUserExistsAsync(string username)
    {
        return await _ldap.UserExistsAsync(username);
    }
}

支持的实现

库提供了以下LDAP目录服务的实现:

  • Linger.Ldap.ActiveDirectory - 针对Microsoft Active Directory的实现
  • Linger.Ldap.Novell - 使用Novell LDAP客户端库的跨平台实现
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 was computed.  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. 
.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.
  • .NETStandard 2.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Linger.Ldap.Contracts:

Package Downloads
Linger.Ldap.ActiveDirectory

Implementation of LDAP client functionality for Active Directory using System.DirectoryServices. Provides Windows-optimized AD connectivity with features for user authentication, information retrieval, group management, and specialized Active Directory operations.

Linger.Ldap.Novell

Implementation of LDAP client functionality using the Novell.Directory.Ldap provider. Provides cross-platform LDAP connectivity with features such as authentication, user information retrieval, group management, and secure connections.

Linger.Ldap.AspNetCore.Identity

C# Helper Library

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.8.4-preview 266 8/25/2025
0.8.3-preview 127 8/20/2025
0.8.2-preview 186 8/4/2025
0.8.1-preview 118 7/30/2025
0.8.0-preview 492 7/22/2025
0.7.2 173 6/3/2025
0.7.1 179 5/21/2025
0.7.0 180 5/19/2025
0.6.0-alpha 191 4/28/2025
0.5.0-alpha 190 4/10/2025
0.4.0-alpha 178 4/1/2025
0.3.3-alpha 183 3/19/2025
0.3.2-alpha 170 3/17/2025
0.3.1-alpha 155 3/16/2025
0.3.0-alpha 232 3/6/2025
0.2.0-alpha 137 2/9/2025
0.1.2-alpha 125 12/17/2024
0.1.1-alpha 113 12/17/2024
0.1.0-alpha 116 12/6/2024
0.0.3-alpha 134 11/27/2024
0.0.2-alpha 97 10/3/2024