Giter Site home page Giter Site logo

ldap-connector's Introduction

Ldap-connector

Build Status Latest Stable Version Total Downloads License

Provides an solution for authentication users with LDAP for Laravel 5.x. It uses ADLDAP library on Adldap2 to create a bridge between Laravel and LDAP

Installation

Laravel 5.1 - 5.0

  1. Install this package through Composer by adding the following line to composer.json

        "dsdevbe/ldap-connector": "3.0.*"

    or you could use command-line

    composer require "dsdevbe/ldap-connector:3.0.*"
  2. Add the service provider in the app configuration by opening config/app.php, and add a new item to the providers array.

    Dsdevbe\LdapConnector\LdapConnectorServiceProvider::class
    
  3. 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',
  4. Publish a new configuration file with php artisan vendor:publish in the configuration folder of Laravel you will find config/ldap.php and modify to your needs. For more detail of the configuration you can always check on ADLAP documentation

    return array(
        'plugins' => array(
            'adldap' => array(
                'account_suffix'=>  '@domain.local',
                'domain_controllers'=>  array(
                    '192.168.0.1',
                    'dc02.domain.local'
                ), // Load balancing domain controllers
                'base_dn'   =>  'DC=domain,DC=local',
                'admin_username' => 'admin', // This is required for session persistance in the application
                'admin_password' => 'yourPassword',
            ),
        ),
    );
    

    Please note that the fields 'admin_username' and 'admin_password' are required for session persistance!

Usage

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' => $username, 'password' => $password)))
{
    return Redirect::intended('dashboard');
}

You can find more examples on Laravel Auth Documentation on using the Auth:: function.

Use AuthController

If you want to use the authentication controller that ships with Laravel you will need to change the following files. By default App\Http\Controllers\Auth\AuthController checks for the email field if nothing is provided. To overwrite this value add the following line in the AuthController.

protected $username = 'username';

Laravel documentation: Authentication Quickstart

Ldap Groups

  • Auth::user()->getGroups() returns array with groups the current user belongs to.
  • Auth::user()->inGroup('GROUPNAME') returns boolean if user belongs to GROUPNAME

Ldap User Information

  • Auth::user()->getUsername() returns authenticated username.
  • Auth::user()->getFirstname() returns authenticated first name.
  • Auth::user()->getLastname() returns authenticated last name.
  • Auth::user()->getEmail() returns authenticated email address.

Laravel 5.2 - ...

  1. Install this package through Composer by adding the following line to composer.json

    "dsdevbe/ldap-connector": "4.0.*"

    or you could use command-line

    composer require "dsdevbe/ldap-connector:4.0.*"
  2. Add the service provider in the app configuration by opening config/app.php, and add a new item to the providers array.

    Dsdevbe\LdapConnector\LdapConnectorServiceProvider::class
    
  3. Change the authentication driver in the Laravel config to use the ldap driver. You can find this in the following file config/auth.php

    'providers' => [
        'users' => [
            'driver' => 'ldap',
            'adldap' => [
                'account_suffix'=>  '@domain.local',
                'domain_controllers'=>  array(
                    '192.168.0.1',
                    'dc02.domain.local'
                ), // Load balancing domain controllers
                'base_dn'   =>  'DC=domain,DC=local',
                'admin_username' => 'admin', // This is required for session persistance in the application
                'admin_password' => 'yourPassword',
            ],
        ],
    ],

    Please note that the fields 'admin_username' and 'admin_password' are required for session persistance!

Usage

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' => $username, 'password' => $password)))
{
    return Redirect::intended('dashboard');
}

You can find more examples on Laravel Auth Documentation on using the Auth:: function.

Use AuthController

If you want to use the authentication controller that ships with Laravel you will need to change the following files. By default App\Http\Controllers\Auth\AuthController checks for the email field if nothing is provided. To overwrite this value add the following line in the AuthController.

protected $username = 'username';

Laravel documentation: Authentication Quickstart

Ldap User Information

Difference with ldap-connector V3 is that now the adLDAP model is directly exposed on the user model. This means that you can fetch all data directly from the user. To access the adldap model you can use now Auth::user()->getAdLDAP().

Examples:

  • Auth::user()->getAdLDAP()->getAccountName()
  • Auth::user()->getAdLDAP()->getFirstName()

To fetch more properties please check adLDAP2 documentation

Contributing

Feel free to contribute to this project for new features or bug fixes. We are open for improvements!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.