#ldap #ldap-3 #async #high-level

simple-ldap

A high-level LDAP client for Rust

7 releases (4 major breaking)

new 5.0.0 Feb 14, 2025
4.0.0 Feb 4, 2025
3.1.0 Feb 4, 2025
2.1.1 Nov 26, 2024
0.0.4 Jun 4, 2023

#125 in Authentication

Download history 143/week @ 2024-10-29 99/week @ 2024-11-05 38/week @ 2024-11-12 9/week @ 2024-11-19 131/week @ 2024-11-26 19/week @ 2024-12-03 40/week @ 2024-12-10 26/week @ 2024-12-31 81/week @ 2025-01-07 44/week @ 2025-01-14 29/week @ 2025-01-21 104/week @ 2025-01-28 423/week @ 2025-02-04 279/week @ 2025-02-11

842 downloads per month
Used in zino-auth

MIT/Apache

75KB
1K SLoC

Simple LDAP client library for Ldap3

A ldap client library that wraps ldap3 to make it easy to use.

CI Crates.io Documentation

Usage

Adding simple_ldap as a dependency to your project:

cargo add simple-ldap

Other useful pieces you'll likely need:

cargo add url serde --features serde/derive

Example

There are plenty more examples in the documentation!

Search records

use simple_ldap::{
    LdapClient, LdapConfig,
    filter::EqFilter,
    ldap3::Scope
};
use url::Url;
use serde::Deserialize;

// A type for deserializing the search result into.
#[derive(Debug, Deserialize)]
struct User {
    uid: String,
    cn: String,
    sn: String,
}


#[tokio::main]
async fn main(){
    let ldap_config = LdapConfig {
        bind_dn: String::from("cn=manager"),
        bind_password: String::from("password"),
        ldap_url: Url::parse("ldaps://localhost:1389/dc=example,dc=com").unwrap(),
        dn_attribute: None,
        connection_settings: None
    };
    let mut client = LdapClient::new(ldap_config).await.unwrap();
    let name_filter = EqFilter::from("cn".to_string(), "Sam".to_string());
    let user: User = client
        .search::<User>(
        "ou=people,dc=example,dc=com",
        Scope::OneLevel,
        &name_filter,
        &vec!["cn", "sn", "uid"],
    ).await.unwrap();
}

Dependencies

~7–22MB
~332K SLoC