Search by

swsn / react-ldap

skydiablo

Async LDAP client for ReactPHP (FreeDSx protocol codec + React transport)

dev-main 2026-10-13 19:02 UTC

This package is auto-updated.

Last update: 2026-10-13 17:08:04 UTC


README

Async LDAP client for ReactPHP.

Protocol encode/decode and LDAP operations come from FreeDSx LDAP (BER/ASN.1, Bind/Search/…, AD-friendly helpers). This package only replaces the blocking FreeDSx socket layer with react/socket + promises.

NamespaceSWSN\ReactLdap\
PHP^8.4
LicenseMIT

Scope (v1)

  • ldap:// (plain) and ldaps:// (TLS from connect)
  • StartTLS after plain connect
  • Simple bind (DN or AD UPN)
  • Search (reuses FreeDSx\Ldap\Operations / Filters / SearchRequest)
  • Unbind / close

Not included yet: SASL, referrals follow, paging/VLV helpers, connection pool.

Usage

use FreeDSx\Ldap\Operations;
use FreeDSx\Ldap\Search\Filters;
use React\EventLoop\Loop;
use SWSN\ReactLdap\LdapClient;

$client = new LdapClient();

$client->connect('ldaps://dc.example.com')
    ->then(fn () => $client->bind('user@example.com', 'secret'))
    ->then(function () use ($client) {
        $request = Operations::search(Filters::equal('mail', 'user@example.com'), 'dn', 'mail')
            ->base('dc=example,dc=com')
            ->useSubtreeScope();

        return $client->search($request);
    })
    ->then(function (\SWSN\ReactLdap\Search\SearchResult $result) use ($client) {
        foreach ($result->entries() as $entry) {
            echo $entry->getDn() . PHP_EOL;
        }

        return $client->unbind();
    })
    ->then(null, function (\Throwable $e) {
        echo $e->getMessage() . PHP_EOL;
    });

Loop::run();

Plain + StartTLS:

$client->connect('ldap://dc.example.com')
    ->then(fn () => $client->startTls())
    ->then(fn () => $client->bind('cn=admin,dc=example,dc=com', 'secret'));

Reuse FreeDSx factories directly (Operations, Filters, Entry, …) — this client only transports them.