ADLDAP 打开 LDAP 身份验证 - 会话未存储 - 返回登录页面



我的环境是一个 laravel 5.8,在 6.0.8 版 Web 应用程序中带有 adldap2 和一个 openLDAP 目录。

几个小时后,我终于可以根据 openLDAP 目录对我的用户进行身份验证,并且数据库导入到 users 表中的工作也有效:

Id name username password remember_token created_at updated_at
King king $2y$10$YF9q7cYqjYnkl.We4Evwv.u/a2sddrfBA3pohgpS2vR... j4AOUHSlkHE3IQW7bsgF7pOIY8EAss6iukfnKhwi2lqXR0eTjE... NULL NULL

当我检查函数中的变量用户时:tryLogin -> $this->guard((->login($user,true(;它来自数据库,似乎很好。但是在我登录后,我还收到消息"重定向到 http://localhost/home.",它返回到登录页面,仍然没有登录。

对于LDAP身份验证,我主要遵循以下示例:即使它有点过时,https://jotaelesalinas.github.io/laravel-simple-ldap-auth/。

我的尝试登录函数如下所示:

protected function attemptLogin(Request $request)
{
$username = Adldap::search()->users()->select('mail','uid','displayName')->findBy('cn', request()->get('username'));
$result = 1;
if($username){
if(Adldap::auth()->attempt($username->getdistinguishedName(), request()->get('password'))){
echo("success");
// Check group
$group = Adldap::search()->groups()->findOrFail('cio');
foreach ($group->getMemberNames() as $name) {
if($name === $username->getAccountName()){
echo("The user is a member of the group.");
$result = 0;
}
} 
if ($result != 0){
$result = 2;
}
} else {
echo("Password wrong");
$result = 1;
}
} else {
echo(request()->get('username') . " not found");
$result = 1;
}
if($result == 0) {
// the user exists in the LDAP server, with the provided password
echo("Everything ok");
$user = AppUser::where($this->username(), $username->getAccountName())->first();
if (!$user) {
// the user doesn't exist in the local database, so we have to create one
$user = new AppUser();
$user->username = $username;
$user->password = '';
// you can skip this if there are no extra attributes to read from the LDAP server
// or you can move it below this if(!$user) block if you want to keep the user always
// in sync with the LDAP server 
//dd($username->getDisplayName());
$sync_attrs = $this->retrieveSyncAttributes($username->getAccountName());
//dd($sync_attrs);
foreach ($sync_attrs as $field => $value) {
$user->$field = $value !== null ? $value : '';
}
}
$this->guard()->login($user, true);
return 0;
}
// the user doesn't exist in the LDAP server or the password is wrong
// log error
return $result;
}

网.php

Route::get('login', 'AuthLoginController@showLoginForm')->name('login');
Route::post('login', 'AuthLoginController@login');
Route::post('logout', 'AuthLoginController@logout')->name('logout');
Route::get('/home', 'HomeController@index')->name('home');

有人知道我错过了什么吗?或者,如果您需要更多信息,请告诉我。似乎未存储会话。

提前致谢

斯蒂芬


再玩几个小时后的小更新。似乎身份验证是在成功登录 null 之后。因此尝试了我可以在互联网上找到的不同方法,例如更改 Web.php路由或将受保护的 $user 变量添加到登录控制器.php但当然没有任何成功。


我发现当我将中间件从身份验证更改为 web 时,我会得到一个会话,但 Auth::User(( 仍然为空

Route::group(['middleware' => 'auth'], function () {
Route::get('/home', 'HomeController@index')->name('home');
}); 

在花费了越来越多的时间后,我终于在这个线程中找到了解决方案: Laravel Auth:try(( 不会持久登录

我的问题是我正在使用"回声"。

这可能让我失去了生命中的几天

最新更新