| Package Data | |
|---|---|
| Maintainer Username: | T3chn0crat | 
| Maintainer Contact: | dens.sascha@gmail.com (Dsdevbe) | 
| Package Create Date: | 2015-05-22 | 
| Package Last Update: | 2015-05-30 | 
| Language: | PHP | 
| License: | MIT | 
| Last Refreshed: | 2025-10-25 15:00:59 | 
| Package Statistics | |
|---|---|
| Total Downloads: | 14 | 
| Monthly Downloads: | 0 | 
| Daily Downloads: | 0 | 
| Total Stars: | 2 | 
| Total Watchers: | 2 | 
| Total Forks: | 3 | 
| Total Open Issues: | 0 | 
This package is a fork of dsdevbe's package (https://github.com/dsdevbe/ldap-connector).
This package will allow you to authenticate to and fetch data from LDAP using Laravel 5.0.x.
It uses adLDAP library to create a bridge between Laravel and LDAP. adLDAP requires PHP 5 and both the LDAP and SSL libraries
Install this package through Composer for Laravel v5.0:
composer require T3chn0crat/laravel-ldap-connector:dev-master
Change the authentication driver in the Laravel config to use the ldap driver. You can find this in the following file config/auth.php
'driver' => 'ldap',
The config/auth.php must also have a valid model set.  That model must include
public function getAuthIdentifier()
{
    if (isset($this->ldap)) {
        return $this->ldap->samaccountname;
    }
}
Create a new configuration file ldap.php in the configuration folder of Laravel app/config/ldap.php and modify to your needs. For more detail of the configuration you can always check on adLDAP documentation
All of these are required
return [
	'account_suffix'=>  "@domain.local",
    // Load balancing domain controllers, but only one is requried
	'domain_controllers'=>  [
        "192.168.0.1", 
        "dc02.domain.local"
    ],
	'base_dn'   =>  'DC=domain,DC=local',
    // AD attributes to get http://msdn.microsoft.com/en-us/library/windows/desktop/ms675090%28v=vs.85%29.aspx
    'fields' => [
        'company',
        'department',
        'displayname',
        'homephone',
        'mail',
        'memberof',
        'mobile',
        'primarygroupid',
        'samaccountname',
        'telephonenumber',
        'title',
    ]
];
Once this is done you arrived at the final step and you will need to add a service provider. Open config/app.php, and add a new item to the providers array.
'T3chn0crat\LdapConnector\LdapConnectorServiceProvider'
The LDAP plugin is an extension of the AUTH class and will act the same as normal usage with Eloquent driver.
if (Auth::attempt(array('username' => $email, 'password' => $password)))
{
    return Redirect::intended('dashboard');
}
You can find more examples on Laravel Auth Documentation on using the Auth:: function.
All the LDAP fields are stored in the Auth::user()->ldap object as public properties.
Email: {{ Auth::user()->ldap->mail }}
Department {{ Auth::user()->ldap->department }}
Will test a user to see if they are a member of the passed in group. Returns a bool
if (Auth::user()->ldap->isMemberOf('Git Hub Users')) { return 'yes'; }
You can use the LdapService object and getAllUsersWithFields to return a Laravel Collection of LdapUserObjects.
$ldap = App::make('T3chn0crat\LdapConnector\LdapService', [Config::get('ldap')]);
$collection = $ldap->getAllUsersWithFields();
You can now apply all the collection function to it. The results will be a collection of LdapUserObjects
$test = $collection->where('mail', 'test@foo.com');
$department = $test->department;