DirectoryTree / LdapRecord-Laravel

Multi-domain LDAP Authentication & Management for Laravel.
https://ldaprecord.com/docs/laravel/v3
MIT License
509 stars 54 forks source link

[Support] Can't connect but binding works #373

Closed Sicklou closed 2 years ago

Sicklou commented 2 years ago

Environment:

Hello,

I'v been trying to use the package for few hours now.

Connection to the LDAP works, but I cannot authenticate.

I tried using the framework agnostic package and it works.

$username = "uid=772718,ou=people,dc=mydc,dc=fr";
$password = "password";

$connection = new Connection([
    'hosts'    => [env('LDAP_CASINO_HOSTS')],
    'username' => env('LDAP_CASINO_USERNAME'),
    'password' => env('LDAP_CASINO_PASSWORD'),
    'port' => env('LDAP_CASINO_PORT')
]);

$connection->connect();
$query = $connection->query();
if($connection->auth()->attempt($username, $password)) {
    echo "It works!";
}

But when I try using the laravel package, using the same credentials, it doesn't work.

$credentials = [
            'username' => $username,
            'password' => $password,
        ];
if(Auth::attempt($credentials))
        {
           echo "ok";
        } else {
            echo "not ok";
        }

I tried all kind of key names, instead of username (dn, uid...), I also tried using mail.

When I dump the object after a query, I find it, I see my email under a "mail" key :

 "mail" => array:2 [▼
    "count" => 1
    0 => arnaud@my-company.com"
  ]

I don't know what I can do to make it work.

Thanks for the package & support.

Sicklou commented 2 years ago

Figured out I had to create a custom User model. The default filters was causing the trouble.

stevebauman commented 2 years ago

Glad you were able to resolve it @Sicklou! Appreciate the quick follow up with your solution 👍