简体   繁体   English

Laravel中的LDAP身份验证

[英]LDAP authentification in Laravel

I am in charge of creating a new laravel project where the authentication is made by our LDAP. 我负责创建一个新的laravel项目,由我们的LDAP进行身份验证。 I am pretty new to laravel so excuse me for my lack of comprehension 我对laravel相当陌生,请原谅我缺乏理解力

I am trying to use this library : Adldap2-Laravel 我正在尝试使用此库: Adldap2-Laravel

I followed this documentation to build the authentification from scratch. 我按照此文档从头开始构建身份验证。

So my config/app.php have those lines added 所以我的config / app.php添加了这些行

//In providers array
Adldap\Laravel\AdldapServiceProvider::class,
Adldap\Laravel\AdldapAuthServiceProvider::class,

//In aliases
'Adldap' => Adldap\Laravel\Facades\Adldap::class,

And my config/auth.php (I also tried to only use the adldap driver, without success) 和我的config / auth.php (我也尝试仅使用adldap驱动程序,但没有成功)

'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => App\User::class,
    ],
    'users' => [
        'driver' => 'adldap',
        'model'  => App\User::class,
    ],
],

Everything looks right. 一切看起来都不错。 But I can not auth, I have this error : These credentials do not match our records. 但是我无法验证,我These credentials do not match our records.此错误: These credentials do not match our records.

When I use this code 当我使用此代码

use Adldap\Laravel\Facades\Adldap;

$username = "myUser";
$password = "myPassword";

if (Adldap::auth()->attempt($username, $password)) {
    //Queries here
}
else
{
    echo "Auth failed";
}

I CAN perform queries, and the authentication works with all my users. 我可以执行查询,并且身份验证适用于所有用户。 But I can not use properly the login form behind the "Login" button. 但是我无法正确使用“登录”按钮后面的登录表单。

Did I miss something ? 我错过了什么 ?


I do not know if the authentication should work directly without importing anything but I also tried to run this command 我不知道身份验证是否应该直接工作而不导入任何内容,但我也尝试运行此命令

php artisan adldap:import

All my users are found and inserted in the laravel DB. 找到我的所有用户,并将其插入laravel DB。 But the authentication still does not work. 但是身份验证仍然不起作用。

I deleted the ADLDAP_ACCOUNT_SUFFIX= from my .env file 我从.env文件中删除了ADLDAP_ACCOUNT_SUFFIX=

And added the suffix directly in ADLDAP_ADMIN_USERNAME=Administrator@mycompany.something 并将后缀直接添加到ADLDAP_ADMIN_USERNAME=Administrator@mycompany.something

Now I'm able to connect via the email address. 现在,我可以通过电子邮件地址进行连接了。

I do not know if it is the best solution but at least it works. 我不知道这是否是最好的解决方案,但至少可以奏效。


I let this post open for a few days to see if someone have a better idea 我让这篇文章开放几天,看看是否有人有更好的主意

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM