Closed markusleitoldZBS closed 3 years ago
Hi @markusleitoldZBS,
Since you're using Plain LDAP authentication (no database synchronization) and your own custom model, you must implement Laravel's Authenticatable
contract onto it, as well as its methods:
namespace App\Ldap;
use LdapRecord\Models\Model;
use Illuminate\Contracts\Auth\Authenticatable;
class User extends Model implements Authenticatable
{
/**
* The object classes of the LDAP model.
*
* @var array
*/
public static $objectClasses = [];
/**
* Get the name of the unique identifier for the user.
*
* @return string
*/
public function getAuthIdentifierName()
{
return 'the-auth-identifier-name';
}
/**
* Get the unique identifier for the user.
*
* @return mixed
*/
public function getAuthIdentifier()
{
return $this->getFirstAttribute('the-auth-identifier');
}
/**
* Get the password for the user.
*
* @return string
*/
public function getAuthPassword()
{
}
/**
* Get the token value for the "remember me" session.
*
* @return string
*/
public function getRememberToken()
{
}
/**
* Set the token value for the "remember me" session.
*
* @param string $value
*
* @return void
*/
public function setRememberToken($value)
{
}
/**
* Get the column name for the "remember me" token.
*
* @return string
*/
public function getRememberTokenName()
{
}
}
You can see the interface on the default Active Directory user model here:
https://github.com/DirectoryTree/LdapRecord/blob/master/src/Models/ActiveDirectory/User.php
And the methods added here:
https://github.com/DirectoryTree/LdapRecord/blob/master/src/Models/Concerns/CanAuthenticate.php
Since you're using some third party LDAP server I don't know about, you'll have to find out what the auth identifier's name and value should be. I cannot help you with that.
I'll keep this issue open while I add this into the documentation for future developers 👍
Hi @stevebauman,
thx a lot for the quick response and clearifying... I pasted your code example in our custom User Model (App/Ldap/User.php), replaced "the-auth-identifier-name" and "the-auth-identifier" with "cn" (as for us the "cn" attribute is unique for each user and I assume this has to be some sort of "primary Key" for the user, right?).
This almost was the solution, I just had to set this additionally in the user model:
protected $guidKey = 'cn';
So the working model now looks like this:
<?php
namespace App\Ldap;
use LdapRecord\Models\Model;
use Illuminate\Contracts\Auth\Authenticatable;
use LdapRecord\Models\Concerns\CanAuthenticate;
class ATUser extends Model implements Authenticatable
{
use CanAuthenticate;
protected $guidKey = 'cn';
/**
* The object classes of the LDAP model.
*
* @var array
*/
public static $objectClasses = [];
/**
* Get the name of the unique identifier for the user.
*
* @return string
*/
public function getAuthIdentifierName()
{
return 'cn';
}
/**
* Get the unique identifier for the user.
*
* @return mixed
*/
public function getAuthIdentifier()
{
return $this->getFirstAttribute('cn');
}
/**
* Get the password for the user.
*
* @return string
*/
public function getAuthPassword()
{
}
/**
* Get the token value for the "remember me" session.
*
* @return string
*/
public function getRememberToken()
{
}
/**
* Set the token value for the "remember me" session.
*
* @param string $value
*
* @return void
*/
public function setRememberToken($value)
{
}
/**
* Get the column name for the "remember me" token.
*
* @return string
*/
public function getRememberTokenName()
{
}
}
Now everything works as expected :)
This is IMHO indeed worth being mentioned in the docs ;)
Environment (please complete the following information):
Describe the bug: In a fresh Laravel 8 App with enabled Vue UI including auth scaffolding (
composer require laravel/ui; php artisan ui vue --auth
) we want authenticate against our LDAP.So we followd the docs here:
https://ldaprecord.com/docs/laravel/v2/installation https://ldaprecord.com/docs/laravel/v2/auth/plain/configuration https://ldaprecord.com/docs/laravel/v2/auth/plain/laravel-ui
As we neither use AD nor openLDAP or FreeIPA as LDAP Backend, we had to make our own LDAP User Model with:
php artisan make:ldap-model User
After entering valid credentials in the login Form and pressing "Login", this Laraval Exception occurs:
Argument 1 passed to LdapRecord\Laravel\Auth\NoDatabaseUserProvider::validateCredentials() must be an instance of Illuminate\Contracts\Auth\Authenticatable, instance of App\Ldap\User given, called in C:\git\laravel-tests\vendor\laravel\framework\src\Illuminate\Auth\SessionGuard.php on line 415
This is the code: config/auth.php:
LoginController.php:
(As we authenticate with username instead of email, "cn" is used, where the username is stored in our LDAP)
App/Ldap/User.php:
login.blade.php:
Any idea whats wrong here?
Thx in advance!