directorytree/ldaprecord-laravel
Integrate LDAP authentication and directory access into Laravel with LdapRecord. Provides user sync, login, Eloquent-style models for LDAP entries, configuration for multiple connections, and utilities for Active Directory and OpenLDAP environments.
RulePassed, RuleFailed) and integrates with Laravel’s logging system, enabling observability and extensibility.Auth system with LDAP-backed providers (e.g., LdapUserProvider). Supports multi-factor authentication (MFA) via custom rules.LdapImporter and ldap:import commands enable one-way or bidirectional sync between LDAP and Laravel databases, with support for scoped imports (v2.7.0+).ldap:browse, ldap:import, and ldap:sync commands for ad-hoc management without UI overhead.memberof lookups). The package mitigates this with caching and query scopes, but benchmarking is recommended for large directories.directorytree/ldaprecord (v4.0+) and Laravel’s Illuminate components. Major version upgrades (e.g., Laravel 13) may require testing.rehashPasswordIfRequired logic (fixed in v3.3.1). Custom providers may need adjustments.memberof vs. uniqueMember)?ext-ldap is enabled and configured.ext-ldap (required).ext-openssl (for TLS), ext-intl (for UTF-8 handling).directorytree/ldaprecord (v4.0+): Underlying LDAP library.ramsey/uuid: For GUID handling (if using LDAP’s entryUUID).Auth::attempt()) and user management (e.g., User model) logic.cn → name, memberOf → groups).composer require directorytree/ldaprecord-laravel
php artisan vendor:publish --provider="DirectoryTree\LdapRecordLaravel\LdapRecordLaravelServiceProvider"
php artisan migrate
config/ldap.php:
'connections' => [
'ad' => [
'host' => 'ldap.example.com',
'port' => 389,
'use_ssl' => true,
'base_dn' => 'dc=example,dc=com',
'username' => 'cn=admin,dc=example,dc=com',
'password' => 'password',
],
],
User):
use DirectoryTree\LdapRecordLaravel\Traits\LdapRecord;
class User extends Authenticatable {
use LdapRecord;
protected $ldapConnection = 'ad';
protected $ldapModel = 'user';
protected $ldapAttributes = [
'uid' => 'username',
'cn' => 'name',
'mail' => 'email',
];
}
Auth::provider() with LdapUserProvider in config/auth.php:
'providers' => [
'ldap' => [
'driver' => 'ldap',
'model' => User::class,
],
],
LoginController to use LDAP rules:
use DirectoryTree\LdapRecordLaravel\Rules\LdapRule;
public function rules() {
return [
'username' => ['required', new LdapRule($this->ldapConnection, 'user')],
];
}
php artisan ldap:import --model=User --connection=ad
$this->actingAsLdapUser('testuser', 'password');
ldap:import with dispatchSync).adldap2 or custom LDAP logic, the package provides drop-in replacements for common operationsHow can I help you explore Laravel packages today?