ptdot / ldapauth
Laravel LDAP身份验证包装器
dev-master
2018-07-22 09:50 UTC
Requires
- php: >=5.5.9
- illuminate/support: 5.3.x|5.4.x|5.5.x|5.6.x
This package is auto-updated.
Last update: 2024-09-21 20:55:56 UTC
README
Laravel LDAP身份验证是一个用于通过轻量级目录访问协议(Lightweight Directory Access Protocol)和Laravel身份验证模型进行身份验证的Active Directory的包。
要求
- Laravel 5.1 - 5.6
- 启用
PHP LDAP
扩展
安装
通过composer安装包。
composer require ptdot/ldapauth
接下来,如果使用的是Laravel 5.5以下版本,请在您的config/app.php
文件中包含服务提供者和Facade。
'providers' => [ Ptdot\LdapAuth\LdapAuthServiceProvider::class, ], 'aliases' => [ 'LdapAuth' => Ptdot\LdapAuth\LdapAuthFacade::class, ]
由于Laravel 5.5+使用了包发现,因此无需手动在app.php
中插入服务提供者和Facade。
配置
使用命令发布配置
php artisan vendor:publish --tag=config
在.env
文件中设置LDAP配置的键和值。
LDAP_HOST=ldap.example.com LDAP_PORT=389
在config/ldap.php
文件中设置您的用户模型或自定义身份验证模型,并记得调整您的身份验证模型的usernameField
值。
确保您数据库中已有用户数据,并为身份验证创建用户模型。
/* |-------------------------------------------------------------------------- | Authentication user model |-------------------------------------------------------------------------- | | Authentication is used User model for default. | Define this option if authentication model using different model / namespace. | */ 'user' => App\User::class, 'usernameField' => 'username'
用法
尝试使用LDAP进行身份验证
$result = LdapAuth::attempt($username, $password);
尝试方法将返回一个数组,指示身份验证是否成功。
示例
/** * Logging in using LDAP */ public funtion login(Request $request) { $username = $request->get('username'); $password = $request->get('password'); $login = LdapAuth::attempt($username, $password); if($login['status']) { return "Login success"; } return "Login failed. Error: ".$login['message']; }
贡献
如果您想帮助这个包变得更好和有用,请随时报告问题或合并请求。