pulasthibandara / Adldap2-Laravel

LDAP Authentication & Management for Laravel

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Adldap2 - Laravel

Built for Laravel Build Status Scrutinizer Code Quality Total Downloads Latest Stable Version License

Description

Adldap2 - Laravel allows easy configuration, access, management and authentication to LDAP connections utilizing the root Adldap2 Repository.

Requirements

To use Adldap2-Laravel, your application and server must meet the following requirements:

  • Larvel 5.*
  • PHP 5.6 or greater
  • PHP LDAP Extension
  • An Active Directory Server

Note: OpenLDAP support is experimental, success may vary.

Index

Installation

Insert Adldap2-Laravel into your composer.json file:

"adldap2/adldap2-laravel": "3.0.*",

Or via command line:

composer require adldap2/adldap2-laravel

Then run composer update.

Once finished, insert the service provider in your config/app.php file:

Adldap\Laravel\AdldapServiceProvider::class,

Then insert the facade:

'Adldap' => Adldap\Laravel\Facades\Adldap::class

Publish the configuration file by running:

php artisan vendor:publish --tag="adldap"

Now you're all set!

Usage

First, configure your LDAP connection in the config/adldap.php file.

Then, you can perform all methods on your Adldap connection through its facade like so:

use Adldap\Laravel\Facades\Adldap;

// Finding a user.
$user = Adldap::search()->users()->find('john doe');

// Searching for a user.
$search = Adldap::search()->where('cn', '=', 'John Doe')->get();

// Authenticating against your LDAP server.
if (Adldap::auth()->attempt($username, $password)) {
    // Passed!
}

// Running an operation under a different connection:
$users = Adldap::getProvider('other-connection')->search()->users()->get();

// Creating a user.
$user = Adldap::make()->user([
    'cn' => 'John Doe',
]);

$user->save();

Or you can inject the Adldap interface into your controllers:

use Adldap\AdldapInterface;

class UserController extends Controller
{
    /**
     * @var Adldap
     */
    protected $adldap;
    
    /**
     * Constructor.
     *
     * @param AdldapInterface $adldap
     */
    public function __construct(AdldapInterface $adldap)
    {
        $this->adldap = $adldap;
    }
    
    /**
     * Displays the all LDAP users.
     *
     * @return \Illuminate\View\View
     */
    public function index()
    {
        $users = $this->adldap->search()->users()->get();
        
        return view('users.index', compact('users'));
    }
}

To see more usage in detail, please visit the Adldap2 Repository.

About

LDAP Authentication & Management for Laravel

License:MIT License


Languages

Language:PHP 100.0%