mauriliobmartins/yii2-ldap-php8

Authorize, search users, get user groups and more from LDAP in Yii2

1.0.0 2025-04-10 20:08 UTC

This package is auto-updated.

Last update: 2025-09-11 14:49:33 UTC


README

This is a fork of the original package created by Vadim E. Kosoukhov, updated to be compatible with PHP 8.

📦 About

The original package was no longer maintained and did not support PHP 8. This fork updates the codebase to ensure full compatibility with modern PHP versions, while preserving the functionality and spirit of the original implementation.

✅ Modifications

The following updates were made in this fork:

  • Updated syntax to support PHP 8
  • Replaced deprecated functions and features
  • Basic testing for PHP 8 compatibility

⚖ License

This project is licensed under the MIT License.

Authorize, search users, get user groups and other from LDAP

Yii2 Latest Stable Version Total Downloads Latest Unstable Version License

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist mauriliobmartins/yii2-ldap-php8

or add

"mauriliobmartins/yii2-ldap-php8": "*"

to the require section of your composer.json file.

Application configuration example:

In config/main.php add:

return [
    'components' => [
        'ldap' => [
            'class' => 'mauriliobmartins\ldap\Connector',
            'useCache' => YII_ENV_DEV ? false : true,
        ],
    ],
    // ...
];

In config/main-local.php add:

return [
    'components' => [
        'ldap' => [
            'host' => 'ldap.example.com',
            'port' => '389',
            'baseDN' => 'OU=...,DC=...,DC=...,DC=net',
            'userDN' => '@....corp.net',
            'groupDN' => '',
            //Input your AD login/pass on dev or sys login/pass on test/prod servers
            'sysUserLogin' => '',
            'sysUserPassword' => '',
        ],
    ],
    // ...
];

Usage example:

if (!Yii::$app->ldap->validateUserCredentials('SAMAccountName', 'password')) {
    throw new ErrorException('Incorrect username or password.');
}
echo Yii::$app->ldap->getUserAttributesBySAMAccountName('SAMAccountName', ['mail', 'sn', 'givenname', 'middlename']);
echo mauriliobmartins\ldap\widgets\UserImage::widget([
    'login' => Yii::$app->user->identity->username,
    'options' => [
        'class' => 'img-circle',
        'alt' => 'User Image',
    ]
]);