I am trying to make authentication with ActiveDirectory using ldaprecord-laravel. I followed the documentation and made required changes in files. However, I ended up with only php artisan ldap:test
working and php artisan ldap:import ldap
showing that there are no users to import.
When I use online LDAP test server, I can go further and make Auth::attempt(['uid' => 'einstein', 'password' => 'password'])
in Tinker, and import works, but the web login still doesn't work. With AD, I can't auth attempt using neither samaccountname
, nor username
, nor uid
. Though plain auth using ldap_connect
and ldap_bind
works.
App/User.php
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Support\Facades\Hash;
use LdapRecord\Laravel\Auth\LdapAuthenticatable;
use LdapRecord\Laravel\Auth\AuthenticatesWithLdap;
class User extends Authenticatable implements LdapAuthenticatable
{
use Notifiable, AuthenticatesWithLdap;
protected $table = 'users';
protected $primaryKey = 'id';
public $timestamps = false;
public $incrementing = false;
/*
public function getAuthPassword()
{
return Hash::make( $this->user_pass );
}
*/
/**
* Настройки пользователя.
*
* @return HasMany
*/
public function settings()
{
return $this->hasMany(Models\Settings::class, 'id', 'id');
}
}
App/Http/Controllers/Auth/LoginController.php
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use LdapRecord\Laravel\Auth\ListensForLdapBindFailure;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers, ListensForLdapBindFailure;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
/**
* Переопределяем переменную, в которой хранится логин пользователя
*
* @return string
*/
public function username()
{
return 'user_login';
}
/**
* Валидация данных на сервере
*
* @param Request $request
*
* @return void
*/
protected function validateLogin(Request $request)
{
$request->validate([
$this->username() => 'required|string',
'password' => 'required|string',
]);
}
protected function credentials(Request $request)
{
return [
'uid' => $request->username,
'password' => $request->password,
];
}
}
How can I find out what causes the problem?