osawereao / adldap
A PHP LDAP Library for Active Directory Manipulation (PHP 8.2+)
Requires
- php: >=8.2
- ext-ldap: *
Requires (Dev)
- mockery/mockery: ^1.6
- pestphp/pest: ^2.0 || ^3.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-28 21:22:38 UTC
README
adLDAP is a PHP class library that provides LDAP authentication and Active Directory management tools, modernized for PHP 8.2+ with native Laravel 9+ package auto-discovery.
Requirements
- PHP:
^8.2(tested with PHP 8.2.35 and PHP 8.5) - PHP LDAP Extension:
ext-ldapenabled in yourphp.ini - OpenSSL Extension (optional): Required if connecting to Active Directory over LDAPS / SSL (
use_ssl => true) or TLS.
Installation & Setup
1. In Laravel (Laravel 9 / 10 / 11)
Step A: Install via Composer
composer require osawereao/adldap
Step B: Publish the Configuration
Laravel auto-discovers the service provider. Run the artisan command to publish config/adldap.php:
php artisan vendor:publish --tag="adldap-config"
Step C: Add your Environment Variables
Open your .env file and configure your Active Directory settings:
ADLDAP_ACCOUNT_SUFFIX=@corp.local ADLDAP_CONTROLLERS=dc1.corp.local,dc2.corp.local ADLDAP_BASE_DN=dc=corp,dc=local ADLDAP_ADMIN_USER=administrator ADLDAP_ADMIN_PASS=SecretPassword ADLDAP_PORT=389 ADLDAP_USE_SSL=false ADLDAP_USE_TLS=false
That's it! The package is ready to use in your controllers and services.
2. Local / Development Setup (Before Packagist Release)
If testing locally in your application before the Packagist release:
- Add a path repository to your project's
composer.json:"repositories": [ { "type": "path", "url": "../adldap" } ], "require": { "osawereao/adldap": "*" }
- Update dependencies:
composer update osawereao/adldap
- Publish configuration:
php artisan vendor:publish --tag="adldap-config"
3. Standalone PHP Usage (Non-Laravel)
composer require osawereao/adldap
use Adldap\Adldap; $config = [ 'account_suffix' => '@corp.local', 'domain_controllers' => ['dc1.corp.local'], 'base_dn' => 'dc=corp,dc=local', 'admin_username' => 'administrator', 'admin_password' => 'SecretPassword', 'ad_port' => 389, 'use_ssl' => false, 'use_tls' => false, ]; $ad = new Adldap($config);
Usage in Laravel
Using the Facade
namespace App\Http\Controllers; use Illuminate\Http\Request; use Adldap\Laravel\Facades\Adldap; class AuthController extends Controller { public function login(Request $request) { $credentials = $request->validate([ 'username' => 'required', 'password' => 'required', ]); if (Adldap::authenticate($credentials['username'], $credentials['password'])) { // Retrieve user details from Active Directory $adUser = Adldap::user()->find($credentials['username']); return response()->json([ 'status' => 'success', 'message' => 'Authenticated successfully', 'user' => [ 'name' => $adUser['displayname'] ?? null, 'email' => $adUser['mail'] ?? null, ] ]); } return response()->json(['error' => 'Invalid credentials'], 401); } }
Using Dependency Injection
use Adldap\Adldap; public function search(Request $request, Adldap $ad) { $users = $ad->search() ->select(['cn', 'mail', 'department']) ->where('department', '=', 'Engineering') ->get(); return response()->json($users); }
Running Tests
Run the test suite via Pest:
./vendor/bin/pest
Or run standalone CLI diagnostics without Composer binaries:
php test_cli.php
Authors & Maintainers
- Anthony Osawere (anthony@osawere.com) - Maintainer
- Richard Hyland - Original Developer
- Steve Bauman - Contributor
- Scott Barnett - Contributor
License
This library is licensed under the LGPL-2.1 License.