Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tyler36/ldap
https://github.com/tyler36/ldap
laravel
Last synced: about 5 hours ago
JSON representation
- Host: GitHub
- URL: https://github.com/tyler36/ldap
- Owner: tyler36
- License: other
- Created: 2020-03-03T04:19:19.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-12-13T05:54:54.000Z (almost 2 years ago)
- Last Synced: 2024-04-23T12:59:11.840Z (5 months ago)
- Topics: laravel
- Language: PHP
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Changelog: changelog.md
- Contributing: contributing.md
- License: license.md
Awesome Lists containing this project
README
# Ldap
[![Latest Version on Packagist][ico-version]][link-packagist]
[![Total Downloads][ico-downloads]][link-downloads]
[![Build Status][ico-travis]][link-travis]
[![StyleCI][ico-styleci]][link-styleci]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.## Installation
Via Composer
``` bash
$ composer require tyler36/ldap
```## Usage
1. Publish the config file```php
$ php artisan vendor:publish --provider="Tyler36\Ldap\LdapServiceProvider"
```2. Update ```.ENV``` with server settings
```
LDAP_HOST=
LDAP_USERNAME=
LDAP_USERNAME_PREFIX=
LDAP_FILTER=
LDAP_DOMAIN_COMP=
LDAP_COMMON_NAME=
LDAP_BASE_DN=
```3. Add a username column to your user migration.
```
$table->string('username')->unique();
```4. Update login view by replacing ```email``` with ```username```. Remember to remove the ```type="email"```
```
```
### Laravel 7
5. Update your ```LoginController``` file. Remember to import ```Tyler36\Ldap\LdapAuthenticator;``````php
/**
* 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);
}
```### laravel/breeze
- Replace the rules section in `app/Http/Requests/Auth/LoginRequest.php`.
```php
public function rules()
{
return config('ldap.rules');
}
```## Change log
Please see the [changelog](changelog.md) for more information on what has changed recently.
## Testing
``` bash
$ composer test
```## Contributing
Please see [contributing.md](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
- [author name][link-author]
- [All Contributors][link-contributors]## License
license. Please see the [license file](license.md) for more information.
[ico-version]: https://img.shields.io/packagist/v/tyler36/ldap.svg?style=flat-square
[ico-downloads]: https://img.shields.io/packagist/dt/tyler36/ldap.svg?style=flat-square
[ico-travis]: https://img.shields.io/travis/tyler36/ldap/master.svg?style=flat-square
[ico-styleci]: https://styleci.io/repos/12345678/shield[link-packagist]: https://packagist.org/packages/tyler36/ldap
[link-downloads]: https://packagist.org/packages/tyler36/ldap
[link-travis]: https://travis-ci.org/tyler36/ldap
[link-styleci]: https://styleci.io/repos/12345678
[link-author]: https://github.com/tyler36
[link-contributors]: ../../contributors