I am trying to authenticate an AD user in laravel using the directorytree/ldaprecord-laravel
package.
I have installed the package and followed the steps as shown in the package install. The script for authenticating looks like this
$connection = Container::getConnection('default');
$user = User::findByOrFail('samaccountname', 'sbauman');
if ($connection->auth()->attempt($user->getDn(), 'SuperSecret')) {
// Credentials are valid!
}
However, I am getting the following error when I try logging in:
message: "LdapRecord\\Laravel\\LdapUserRepository::createModel(): Return value must be of type LdapRecord\\Models\\Model, App\\Models\\User returned"
Have you tried extending your User model to, LdapRecord\Models\Model ? and added your LDAP classes to public static array $objectClasses ?
As per documentation, you must, add public static property that contains the object classes of the LDAP record.
These object classes are used to locate the proper objects in your LDAP directory.
<?php
use LdapRecord\Models\Model;
class User extends Model
{
public static array $objectClasses = [
'top',
'person',
'organizationalperson',
'user',
];
}