chrmorandi / yii2-ldap
LDAP
v1.1.1
2022-09-01 11:16 UTC
Requires
- php: >=8.0
- ext-ldap: *
- yiisoft/yii2: *
Requires (Dev)
This package is auto-updated.
Last update: 2024-08-30 01:12:50 UTC
README
此扩展为Yii框架2.0提供LDAP集成。它包括基本的查询/搜索支持,并实现了ActiveRecord模式,允许您将活动记录存储在Active Directory或OpenLDAP中。
要求
要使用yii2-ldap,您的服务器必须支持
PHP LDAP 扩展
安装
安装此扩展的首选方式是通过 composer。
运行以下命令
php composer.phar require --prefer-dist chrmorandi/yii2-ldap
或将其添加到composer.json文件的require部分
"chrmorandi/yii2-ldap": "*"
。
配置
return [ //.... 'components' => [ 'ldap' => [ 'class' => 'chrmorandi\ldap\Connection', // Mandatory Configuration Options 'dc' => [ '192.168.1.1', 'ad.com' ], 'baseDn' => 'dc=ad,dc=com', 'username' => 'administrator@ad.com', 'password' => 'password', // Optional Configuration Options 'port' => 389, 'followReferrals' => false, 'useTLS' => true, // Change pageSize (e.g. to 1000) if you are getting the following message // with large result sets: // ldap_search(): Partial search results returned: Sizelimit exceeded 'pageSize' => -1, ], ] ];
用户认证
要使用您的AD服务器进行用户认证,请调用您的提供者的Yii::$app->ldap->auth()
方法
try { if (Yii::$app->ldap->auth($this->username, $password)) { // Credentials were correct. } else { // Credentials were incorrect. } } catch (Exception $e) { // error }