kadotafig / yii2-ldaprecord
Yii2 extension for library LdapRecord
Package info
github.com/kadotafig/yii2-ldaprecord
Type:yii2-extension
pkg:composer/kadotafig/yii2-ldaprecord
v0.2.5
2021-08-29 23:59 UTC
Requires
- php: >=7.2
- directorytree/ldaprecord: 2.6.*
- yiisoft/yii2: 2.0.*
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Documentation for LdapRecord
Documentation for ZimbraLDAP
Installation
The preferred way to install this extension is through composer.
php composer.phar require --prefer-dist kadotafig/yii2-ldaprecord "*"
or add
"kadotafig/yii2-ldaprecord": "*"
to the require section of your composer.json file.
Configuration
'components' => [ ... 'ldap' => [ 'class' => kadotafig\ldaprecord\LdapRecord::class, 'providers' => [ 'ad' => [ 'class' => kadotafig\ldaprecord\LdapRecord::class, // Mandatory Configuration Options 'hosts' => ['192.168.1.1'], 'base_dn' => 'dc=local,dc=com', 'username' => 'admin@local.com', 'password' => 'password', // Optional Configuration Options 'port' => 389, 'follow_referrals' => false, 'use_ssl' => false, 'use_tls' => false, 'version' => 3, 'timeout' => 5, // Custom LDAP Options 'options' => [ // See: http://php.net/ldap_set_option LDAP_OPT_X_TLS_REQUIRE_CERT => LDAP_OPT_X_TLS_HARD ], ], 'ldap' => [ 'hosts' => ['192.168.1.2'], 'base_dn' => 'dc=local,dc=com', 'username' => 'cn=admin,dc=mts,dc=by', 'password' => 'password', // Optional Configuration Options 'port' => 389, 'version' => 3, // Custom LDAP Options 'options' => [ // See: http://php.net/ldap_set_option LDAP_OPT_X_TLS_REQUIRE_CERT => LDAP_OPT_X_TLS_HARD ], ], ], 'zimbra' => [ 'hosts' => ['192.168.1.2'], 'base_dn' => 'dc=local,dc=com', 'username' => 'cn=admin,dc=mts,dc=by', 'password' => 'password', // Optional Configuration Options 'port' => 389, 'version' => 3, // Custom LDAP Options 'options' => [ // See: http://php.net/ldap_set_option LDAP_OPT_X_TLS_REQUIRE_CERT => LDAP_OPT_X_TLS_HARD ], ], ], ], ... ],
Usage
Simple usage without a user model
Query:
Yii::$app->ldap->initProvider('ad')->query()->where('cn', '=', 'John Doe')->get();
Authentication:
Yii::$app->ldap->initProvider('ad')->auth()->attempt('username', 'password', true);
Simple usage with a model
Model:
class User extends \LdapRecord\Models\ActiveDirectory\User { /** * The "booting" method of the model. * @throws \LdapRecord\Auth\BindException * @throws \LdapRecord\ConnectionException */ protected static function boot() { Yii::$app->ldap->initProvider('ad'); } protected $connection = 'ad'; }
$user = User::findByGuid('guid');