This package is designed to offer a quick authentication process via LDAP.
The example below describes a setup that authenticates using a username
and ```password`` combination.
Via Composer
$ composer require tyler36/ldap
- Publish the config file
$ php artisan vendor:publish --provider="Tyler36\Ldap\LdapServiceProvider"
- Update
.ENV
with server settings
LDAP_HOST=
LDAP_USERNAME=
LDAP_USERNAME_PREFIX=
LDAP_FILTER=
LDAP_DOMAIN_COMP=
LDAP_COMMON_NAME=
LDAP_BASE_DN=
- Add a username column to your user migration.
$table->string('username')->unique();
- Update login view by replacing
email
withusername
. Remember to remove thetype="email"
<input id="username"
class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline{{ $errors->has('username') ? ' border-red-500' : '' }}"
name="username" value="{{ old('username') }}" required autofocus>
- Update your
LoginController
file. Remember to importTyler36\Ldap\LdapAuthenticator;
/**
* Get the login username to be used by the controller. ['email']
*
* @return string
*/
public function username()
{
return config('ldap.username');
}
/**
* Attempt to log the user into the application.
*
* @param \Illuminate\Http\Request $request
*
* @return mixed
*/
protected function attemptLogin(Request $request)
{
// This is where authentication happens. It SHOULD return an array containing the user
$ldap = new LdapAuthenticator($request);
$ldapUser = $ldap->authenticate();
if (!$ldapUser || 'array' !== gettype($ldapUser)) {
return $ldapUser;
}
// Un-comment the following to see details of the user array
// dd($ldapUser)
// Update or create a new user based on the username. The second array determines how to populate new users.
$user = User::updateOrCreate(
[$this->username() => $request->get('username')],
[
$this->username() => $request->get('username'),
'name' => optional($ldapUser)['displayname'][0],
'email' => optional($ldapUser)['mail'][0],
]
);
auth()->login($user);
}
- Replace the rules section in
app/Http/Requests/Auth/LoginRequest.php
.
public function rules()
{
return config('ldap.rules');
}
Please see the changelog for more information on what has changed recently.
$ composer test
Please see contributing.md for details and a todolist.
If you discover any security related issues, please email author email instead of using the issue tracker.
license. Please see the license file for more information.