#async #ldap #high-level

simple-ldap

A high-level LDAP client for Rust

8 releases (5 major breaking)

6.0.1 Apr 17, 2025
5.1.0 Feb 26, 2025
4.0.0 Feb 4, 2025
3.1.0 Feb 4, 2025
0.0.4 Jun 4, 2023

#264 in Authentication

Download history 7/week @ 2025-01-01 92/week @ 2025-01-08 36/week @ 2025-01-15 26/week @ 2025-01-22 277/week @ 2025-01-29 249/week @ 2025-02-05 237/week @ 2025-02-12 40/week @ 2025-02-19 182/week @ 2025-02-26 39/week @ 2025-03-05 16/week @ 2025-03-12 1/week @ 2025-03-26 1/week @ 2025-04-02 57/week @ 2025-04-09 219/week @ 2025-04-16

278 downloads per month

MIT/Apache

88KB
1.5K 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;
use serde_with::serde_as;
use serde_with::OneOrMany;

// A type for deserializing the search result into.
#[serde_as] // serde_with for multiple values
#[derive(Debug, Deserialize)]
struct User {
    uid: String,
    cn: String,
    sn: String,
    #[serde_as(as = "OneOrMany<_>")]
    addresses: Vec<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","addresses"],
    ).await.unwrap();
}

Dependencies

~8–23MB
~347K SLoC