2017 © Pedro Peláez
 

library eloquent-ldap

A Laravel package that first tries to log the user against the internal database if that fails, it tries against the configured LDAP/AD server.

image

sroutier/eloquent-ldap

A Laravel package that first tries to log the user against the internal database if that fails, it tries against the configured LDAP/AD server.

  • Saturday, January 20, 2018
  • by sroutier
  • Repository
  • 2 Watchers
  • 15 Stars
  • 6,297 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 6 Forks
  • 1 Open issues
  • 15 Versions
  • 2 % Grown

The README.md

eloquent-ldap

Latest Version on Packagist Software License, (*1)

A Laravel package that first tries to log the user against the internal database, if that fails, it tries against the configured LDAP/AD server. Optionally it will create a local user record on first login of an LDAP user, as well as grant that user permissions to local groups that have matching names of the LDAP groups that the user is a member of., (*2)

Version Compatibility

Laravel LERN
5.1.x 1.x
5.5.x 2.x

Install

Via Composer, (*3)

``` bash $ composer require sroutier/eloquent-ldap, (*4)


## Declare provider Add this declaration in the provider array of your `./config/app.php` file: ``` php Sroutier\EloquentLDAP\Providers\EloquentLDAPServiceProvider::class,

Publish assets

To publish the assets, config file and migration scripts, run this command:, (*5)

``` bash $ php artisan vendor:publish --provider="Sroutier\EloquentLDAP\Providers\EloquentLDAPServiceProvider", (*6)


This will publish a config file and a migration file. ## Migration The migration script will add a new column `auth_type` to the schema of the `users` table, and one column `resync_on_login` to the `groups` table. You should already have both tables, but if you do not or if you want to use different tables for those purposes, the migration to create those tables is provided as an example, but commented out. You will want to review the migration script and adjust according to your scenario. Once ready, run the migration script with this command: ``` bash $ php artisan migrate

Configure

The recommended way to configure this package is by defining the following variables in you .env file and adjusting the values there. For a detailed explanation of each setting, refer to the config file that you published above., (*7)

The configuration that you will need will vary based on the type or server that you wish to authenticate against. Below are example config section for both options, Lightweight Directory Access Protocol (LDAP) and Microsoft Active Directory (MSAD)., (*8)

Microsoft Active Directory server.

Below is a section of a .env config file that shows how to configure your system to access a Microsoft Active Directory server:, (*9)

eloquent-ldap.enabled=true
eloquent-ldap.debug=false
eloquent-ldap.server_type=MSAD
eloquent-ldap.create_accounts=true
eloquent-ldap.replicate_group_membership=true
eloquent-ldap.resync_on_login=true
eloquent-ldap.group_model=App\Models\Role
eloquent-ldap.label_internal=internal
eloquent-ldap.label_ldap=ldap
eloquent-ldap.account_suffix=@company.com
eloquent-ldap.base_dn=DC=department,DC=company,DC=com
eloquent-ldap.server=ldapsrv01.company.com
eloquent-ldap.port=389
eloquent-ldap.user_name=ldap_reader
eloquent-ldap.password=PaSsWoRd
eloquent-ldap.return_real_primary_group=true
eloquent-ldap.secured=false
eloquent-ldap.secured_port=636
eloquent-ldap.recursive_groups=true
eloquent-ldap.sso=false
eloquent-ldap.username_field=samaccountname
eloquent-ldap.email_field=userprincipalname
eloquent-ldap.first_name_field=givenname
eloquent-ldap.last_name_field=sn
eloquent-ldap.user_filter=(&(objectcategory=person)(samaccountname=%username))

Lightweight Directory Access Protocol server.

Below is a section of a .env config file that shows how to configure your system to access a Lightweight Directory Access Protocol server:, (*10)

eloquent-ldap.enabled=true
eloquent-ldap.debug=false
eloquent-ldap.server_type=LDAP
eloquent-ldap.create_accounts=true
eloquent-ldap.replicate_group_membership=false
eloquent-ldap.resync_on_login=false
eloquent-ldap.group_model=App\Models\Role
eloquent-ldap.label_internal=internal
eloquent-ldap.label_ldap=ldap
eloquent-ldap.account_suffix=
eloquent-ldap.base_dn=dc=example,dc=com
eloquent-ldap.server=ldap.forumsys.com
eloquent-ldap.port=389
eloquent-ldap.user_name=cn=read-only-admin,dc=example,dc=com
eloquent-ldap.password=password
eloquent-ldap.return_real_primary_group=true
eloquent-ldap.secured=false
eloquent-ldap.secured_port=636
eloquent-ldap.recursive_groups=true
eloquent-ldap.sso=false
eloquent-ldap.username_field=uid
eloquent-ldap.email_field=mail
eloquent-ldap.first_name_field=
eloquent-ldap.last_name_field=sn
eloquent-ldap.user_filter=(&(objectclass=person)(uid=%username))

NOTE: THe configuration options above will allow you to connect and authenticate users using the publicly available OpenLDAP test server hosted by Forum Systems., (*11)

MSAD vs LDAP

A couple of difference in how to configure the system depending on which server type is being used are worth pointing out., (*12)

  • eloquent-ldap.server_type: Can be either LDAP or MSAD. Lets the system know how to interact with the authentication server.
  • eloquent-ldap.replicate_group_membership: Currently only supported for MSAD servers.
  • eloquent-ldap.resync_on_login: Currently only supported for MSAD servers.
  • eloquent-ldap.account_suffix:
    • LDAP: Should remain empty for LDAP servers.
    • MSAD: Should contain the static part of the users email address.
  • eloquent-ldap.user_name:
    • LDAP: Should be the complete DN of the user to bind with.
    • MSAD: Simply the name of the user to bind with.
  • eloquent-ldap.return_real_primary_group:
    • LDAP: Not used.
    • MSAD: Fix Microsoft AD not following standards may incur extra processing.

Usage

The users table/model must have the following columns/attributes named username, first_name, last_name and email. The migration script provided with this package has an example of how to create such a table but it is commented out., (*13)

The user model must have the auth-type attribute added to its fillable array to allow setting the column in the database., (*14)

Also your login view and AuthController must accept a user name and password. They can accept other fields if you want, such as email, security token, etc... But the first time a new user tries to log in, since he will not be found in the local database, the package will need the user name to authenticate against the LDAP server., (*15)

Example

For a concrete example of this package used in an active project, see sroutier/laravel-5.1-enterprise-starter-kit. Note that in that project this package is used in combination with Zizaco/entrust to provide role based authorization, therefore there is no group model, but instead a role model., (*16)

Change log

Please see CHANGELOG for more information what has changed recently., (*17)

Contributing

Please see CONTRIBUTING for details., (*18)

Security

If you discover any security related issues, please email sroutier@gmail.com instead of using the issue tracker., (*19)

Credits

License

The GNU General Public License Version 3 (GPLv3). Please see License File for more information., (*20)

The Versions

20/01 2018

dev-master

9999999-dev https://github.com/sroutier/eloquent-ldap

A Laravel package that first tries to log the user against the internal database if that fails, it tries against the configured LDAP/AD server.

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

laravel authentication auth eloquent ldap active directory ad ldap-eloquent

14/11 2017

2.0

2.0.0.0 https://github.com/sroutier/eloquent-ldap

A Laravel package that first tries to log the user against the internal database if that fails, it tries against the configured LDAP/AD server.

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

laravel authentication auth eloquent ldap active directory ad ldap-eloquent

21/03 2017

dev-l51

dev-l51 https://github.com/sroutier/eloquent-ldap

A Laravel package that first tries to log the user against the internal database if that fails, it tries against the configured LDAP/AD server.

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

laravel authentication auth eloquent ldap active directory ad ldap-eloquent

21/03 2017

1.0

1.0.0.0 https://github.com/sroutier/eloquent-ldap

A Laravel package that first tries to log the user against the internal database if that fails, it tries against the configured LDAP/AD server.

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

laravel authentication auth eloquent ldap active directory ad ldap-eloquent

15/12 2016

0.1.10

0.1.10.0 https://github.com/sroutier/eloquent-ldap

A Laravel package that first tries to log the user against the internal database if that fails, it tries against the configured LDAP/AD server.

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

laravel authentication auth eloquent ldap active directory ad ldap-eloquent

08/11 2016

0.1.9

0.1.9.0 https://github.com/sroutier/eloquent-ldap

A Laravel package that first tries to log the user against the internal database if that fails, it tries against the configured LDAP/AD server.

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

laravel authentication auth eloquent ldap active directory ad ldap-eloquent

21/09 2016

0.1.8

0.1.8.0 https://github.com/sroutier/eloquent-ldap

A Laravel package that first tries to log the user against the internal database if that fails, it tries against the configured LDAP/AD server.

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

laravel authentication auth eloquent ldap active directory ad ldap-eloquent

19/08 2016

0.1.7

0.1.7.0 https://github.com/sroutier/eloquent-ldap

A Laravel package that first tries to log the user against the internal database if that fails, it tries against the configured LDAP/AD server.

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

laravel authentication auth eloquent ldap active directory ad ldap-eloquent

02/05 2016

0.1.6

0.1.6.0 https://github.com/sroutier/eloquent-ldap

A Laravel package that first tries to log the user against the internal database if that fails, it tries against the configured LDAP/AD server.

  Sources   Download

GPLv3

The Requires

 

The Development Requires

laravel authentication auth eloquent ldap active directory ad ldap-eloquent

02/05 2016

0.1.5

0.1.5.0 https://github.com/sroutier/eloquent-ldap

A Laravel package that first tries to log the user against the internal database if that fails, it tries against the configured LDAP/AD server.

  Sources   Download

GPLv3

The Requires

 

The Development Requires

laravel authentication auth eloquent ldap active directory ad ldap-eloquent

02/05 2016

0.1.4

0.1.4.0 https://github.com/sroutier/eloquent-ldap

A Laravel package that first tries to log the user against the internal database if that fails, it tries against the configured LDAP/AD server.

  Sources   Download

GPLv3

The Requires

 

The Development Requires

laravel authentication auth eloquent ldap active directory ad ldap-eloquent

11/04 2016

0.1.3

0.1.3.0 https://github.com/sroutier/eloquent-ldap

A Laravel package that first tries to log the user against the internal database if that fails, it tries against the configured LDAP/AD server.

  Sources   Download

GPLv3

The Requires

 

The Development Requires

laravel authentication auth eloquent ldap active directory ad ldap-eloquent

28/08 2015

0.1.2

0.1.2.0 https://github.com/sroutier/eloquent-ldap

A Laravel package that first tries to log the user against the internal database if that fails, it tries against the configured LDAP/AD server.

  Sources   Download

GPLv3

The Requires

 

The Development Requires

laravel authentication auth eloquent ldap active directory ad ldap-eloquent

08/08 2015

0.1.1

0.1.1.0 https://github.com/sroutier/eloquent-ldap

A Laravel package that first tries to log the user against the internal database if that fails, it tries against the configured LDAP/AD server.

  Sources   Download

GPLv3

The Requires

 

The Development Requires

laravel authentication auth eloquent ldap active directory ad ldap-eloquent

07/08 2015

0.1.0

0.1.0.0 https://github.com/sroutier/eloquent-ldap

A Laravel package that first tries to log the user against the internal database if that fails, it tries against the configured LDAP/AD server.

  Sources   Download

GPLv3

The Requires

 

The Development Requires

laravel authentication auth eloquent ldap active directory ad ldap-eloquent