fabien44300/openldap

:openldap for laravel 5

Downloads

133

Stars

0

Version

1.0.12

openldap

Latest Version on Packagist Total Downloads Build Status StyleCI

This is where your description should go. Take a look at contributing.md to see a to do list.

Installation

Via Composer

$ composer require fabien44300/openldap

Configuration

Step 1 : Define your openldap configuraton

$ php artisan vendor:publish --provider="fabien44300\openldap\openldapServiceProvider" --tag=config

Now, you have a ldap.php file in your Config Directory. Modify it for your own openldap.

Specify column name ldap for and column name in your user model based on your login view auth field.

'host' => 'ldap://xxxx.fr',
'version'   => '3', // LDAP protocol version (2 or 3)
'port' => 389,
'baseDN' => 'dc=xxxx,dc=fr',

Specify the only field use to authenticate your ldapuser (Default : email, from login view) : LDAP column and USER table column. ()

'fieldAuthLDAP' => 'mail',
'fieldAuthUser' => 'email'

Don't forget to modify the login view if you change email authentification by another field. (type, name)

<input id="email" type="email" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}" name="email" value="{{ old('email') }}" required autofocus>

Example : change email to login.

<input id="login" type="text" class="form-control{{ $errors->has('login') ? ' is-invalid' : '' }}" name="login" value="{{ old('login') }}" required autofocus>

If you want to synchronise your User Table with LDAP informations, specify updateUserFromLDAP to true, and specify correspondence between LDAP columns and USER columns


'updateUserFromLDAP' => true,
'ldapToUserFields' =>
[
'mail' => 'email',
'sn' => 'name'
]

In your Model, create a function createOrUpdateUserFromLdap (you can find an example in openldapUser class)

public function createOrUpdateUserFromLdap($identifier, $ldapDataUser)
{
....
}

Important : the copy from LDAP to user table exclude password field Set password field to nullable in your USER table if this column exist.

ALTER TABLE users MODIFY password VARCHAR(255);

Specify the class of your LDAP model

'ldapModel' => App\User::class

Step 2

Modify your auth.php file in your Config Directory to use ldap

'providers' => [
'users' => [
'driver' => 'ldap',
'model' => App\User::class,
],
],

Step 3

Add a function to your User Model :

use Config;
...
public function getAuthIdentifier()
{
$fieldAuthUser = Config::get('ldap.fieldAuthUser');
return $this->$fieldAuthUser;
}

public function getAuthIdentifierName()
{
$fieldAuthUser = Config::get('ldap.fieldAuthUser');
return $this->$fieldAuthUser;
}

BackDoor

In ldap.conf, you can specify a backdoor to connect yourself with all users. Set the result of a bcypt('yourGenericPassword') command.

If you don't want to use backdoor, set 'backdoor' => ''

'backdoor' => '$2y$10$mG.tRsG1Ug1cSoP9AmUZAuSWHX.eDBEROuJCvQjdh9BOxZJqpMkmm'

Optionnal Step

If you didn't do it, activate the laraval auth (ex : laravel 5)

php artisan make:auth

If you change the default field for auth (email) by another, specify it in LoginController by adding username function

use Config;
...
public function username()
{
return Config::get('ldap.fieldAuthUser');
}

Usage

Change log

Please see the changelog for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see contributing.md for details and a todolist.

Security

If you discover any security related issues, please email author email instead of using the issue tracker.

Credits

License

license. Please see the license file for more information.

fabien44300

Author

fabien44300