futuretek / yii2-ldap
LDAP
dev-master
2018-06-07 14:12 UTC
Requires
- php: >=5.6
- ext-ldap: *
- yiisoft/yii2: *
Requires (Dev)
This package is auto-updated.
Last update: 2024-09-29 05:08:24 UTC
README
此扩展为Yii框架2.0提供了LDAP集成。它包括基本的查询/搜索支持,并实现了ActiveRecord模式,允许您在Active Directory或OpenLDAP中存储活动记录。
要求
要使用yii2-ldap,您的服务器必须支持
PHP LDAP扩展
安装
安装此扩展的首选方式是通过 composer。
运行以下命令之一
php composer.phar require --prefer-dist chrmorandi/yii2-ldap
或
"chrmorandi/yii2-ldap": "*"
将其添加到composer.json文件的要求部分。
配置
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 } }