Laravel 5 Active Directory LDAP Authentication driver.

Overview

Build Status Total Downloads Latest Stable Version License

Active Directory LDAP Authentication

Laravel 5 Active Directory LDAP Authentication driver.

Fork

This is a fork of Cody Covey's ldap-auth package. Unfortunately he doesn't developed the package recently and didn't update the package to Laravel 4.1+ or even Laravel 5. Therefore I decided to fork the package to provide a minimal Laravel 5 support.

The first release, 2.0, isn't well tested. Just be careful!

Contribution

Just post an issue or create a pull request on this repository. I'll really appreciate it.

Installation

Versions

This will follow releases similar to how Laravel itself manages releases. When Laravel moves to 5.2 this package will move to 2.2, with minor versions signifying bug fixes, etc.

Laravel Version Package Version Package Status
5.1.x 2.1.* maintained
5.0.x 2.1.* maintained
5.0.x 2.0.* abandoned
4.x 1.0.* abandoned

Version 2.1 requires PHP 5.5+. If you are using Laravel 5.0 which supports PHP 5.4 you can still use 2.0.*. However, this version won't get updates.

Laravel 5.1 / 5.0

To install this package pull it in through Composer.

composer require strebl/l5-ldap-auth:2.1.*

After Composer is done, you need to tell your application to use the LDAP service provider.

Open config/app.php and add the service provider

Ccovey\LdapAuth\LdapAuthServiceProvider::class

after

Illuminate\Auth\AuthServiceProvider::class

This tells Laravel to use the service provider from the vendor folder.

You also need to direct Auth to use the ldap driver instead of Eloquent or Database, edit config/auth.php and change driver to ldap:

    'driver' => 'ldap',

Laravel 4

The Laravel 4 version of this package is no longer maintained.

To install this package pull it in through Composer.

composer require strebl/l5-ldap-auth:1.0.*

After Composer is done, you need to tell your application to use the LDAP service provider.

Open config/app.php and find

Illuminate\Auth\AuthServiceProvider

and replace it with

Ccovey\LdapAuth\LdapAuthServiceProvider

This tells Laravel to use the service provider from the vendor folder.

You also need to direct Auth to use the ldap driver instead of Eloquent or Database, edit app/config/auth.php and change driver to ldap

Configuration

To specify the username field to be used in config/auth.php (Laravel 4: app/config/auth.php) set a key / value pair 'username_field' => 'fieldname' This will default to username if you don't provide one.

To set up your adLDAP for connections to your domain controller, create a file config/adldap.php (Laravel 4: app/config/adldap.php) This will provide all the configuration values for your connection. For all configuration options an array like the one below should be provided.

It is important to note that the only required options are account_suffix, base_dn, and domain_controllers. The others provide either security or more information. If you don't want to use the others simply delete them.

array("dc1.domain.local", "dc2.domain.local"), // An array of domains may be provided for load balancing. 'base_dn' => 'DC=domain,DC=local', 'admin_username' => 'user', 'admin_password' => 'password', 'real_primary_group' => true, // Returns the primary group (an educated guess). 'use_ssl' => true, // If TLS is true this MUST be false. 'use_tls' => false, // If SSL is true this MUST be false. 'recursive_groups' => true, ]; ">
// Example adldap.php file.
return [
	'account_suffix' => "@domain.local",

	'domain_controllers' => array("dc1.domain.local", "dc2.domain.local"), // An array of domains may be provided for load balancing.

	'base_dn' => 'DC=domain,DC=local',

	'admin_username' => 'user',

	'admin_password' => 'password',
	
	'real_primary_group' => true, // Returns the primary group (an educated guess).

	'use_ssl' => true, // If TLS is true this MUST be false.

	'use_tls' => false, // If SSL is true this MUST be false.

	'recursive_groups' => true,
];

Usage

$guarded is now defaulted to all so to use a model you must change to $guarded = []. If you store Roles or similar sensitive information make sure that you add that to the guarded array.

Use of Auth is the same as with the default service provider.

By Default this will have the username (samaccountname), displayname, primary group, as well as all groups user is a part of

To edit what is returned you can specify in config/auth.php (Laravel 4: app/config/auth.php) under the fields key.

For more information on what fields from AD are available to you visit http://goo.gl/6jL4V

You may also get a complete user list for a specific OU by defining the userList key and setting it to true. You must also set the group key that defined which OU to look at. Do not that on a large AD this may slow down the application.

Model Usage

You can still use a model with this implementation as well if you want. ldap-auth will take your fields from ldap and attach them to the model allowing you to access things such as roles / permissions from the model if the account is valid in Active Directory. It is also important to note that no authentication takes place off of the model. All authentication is done from Active Directory and if they are removed from AD but still in a users table they WILL NOT be able to log in.

Comments
  • BindingResolutionException in Container.php line 744: Target [Illuminate\Contracts\Auth\Access\Gate] is not instantiable.

    BindingResolutionException in Container.php line 744: Target [Illuminate\Contracts\Auth\Access\Gate] is not instantiable.

    Hello, I'm receiving the following error when trying to configure this package on the newest version of Laravel (5.1.1).

    BindingResolutionException in Container.php line 744: Target [Illuminate\Contracts\Auth\Access\Gate] is not instantiable.

    Any help would be greatly appreciated.

    opened by brockwddb 10
  • Can't Access AD Properties of Logged In User

    Can't Access AD Properties of Logged In User

    Hello -

    I'm running into a few problems that I'm having trouble overcoming, which is accessing the properties that are available to the Active Directory user, such as their full name, groups, etc.

    As per the documentation that is provided, adding the fields value to the auth.php configuration file should make them accessible, but it appears it isn't working properly.

    'fields' => ['displayname', 'givenname']
    

    I added the above line, but when trying to access the logged in user's display name, it always returns null.

    return dd(\Auth::user()->displayname); // returns null
    

    Any help would be greatly appreciated. Thank you for your help!

    opened by brockwddb 8
  • Active Directory groups, custom username field, null groups

    Active Directory groups, custom username field, null groups

    Hello,

    This is my first pull request so please let me know if I am not following GitHub etiquette.

    I have a few bug fixes for the project. One of these has already been proposed by @jtpenny concerning Windows groups so I just want to make sure he gets credit for that fix. I have tested it and it works in our environment with AD (thank you!)

    The other part of that commit is for fixing a bug where the user specified username field is set to the key 'username' instead of the function for getting the username.

    Lastly, there is a bug where an offset error occurs in the retrieveByCredentials() function if a non-existent username is passed to that function, so it can't find the groups (returns null) which causes problems further down the line in the InfoCollection.

    Let me know if you have any questions. Thanks for this project, it is extremely useful!

    opened by marknduncan 7
  • getAllGroups() returns Key=Value Array

    getAllGroups() returns Key=Value Array

    Hi strebl,

    is there a proper reason why you are doing this? https://github.com/strebl/ldap-auth/blob/master/src/LdapAuthUserProvider.php#L268 Just returning $groups would make more sense for me.

    Best regards, ChrOst

    opened by ChrOst 4
  • Configuration issue

    Configuration issue

    I found that this part:

    To set up your adLDAP for connections to your domain controller, create a file app/config/adldap.php This will provide all the configuration values for your connection.

    was incorrect. I had to add the config options to ConfigServiceProvider.php

    opened by collinsjd 4
  • ErrorException in LdapAuthUserProvider.php line 249: Undefined offset: 1

    ErrorException in LdapAuthUserProvider.php line 249: Undefined offset: 1

    New to Github so not really sure where to post this, but I was getting this error when trying to log in with an account that didn't exist.

    Changing to the following seemed to fix it.

    return count($groups) > 1 ? substr($groups[1], '3') : null;
    
    opened by spaldos 3
  • logic error in getAllGroups()

    logic error in getAllGroups()

    I'm not an LDAP guy, so maybe this is only for us, but in LdapAuthUserProvider.php:269 says

                        if (substr($splitGroup, 0, 3) !== 'DC=') {
                            $grps[substr($splitGroup, '3')] = substr($splitGroup, '3');
                        }
    

    Our groups return without the "DC=", so my groups array in Laravel looks like:

    "groups": {
        "ain Users": "ain Users",  // should be "Domain Users"
        "rs": "rs"  // should be "Users"
    }
    

    If the purpose is to replace out the strings that start with DC=, then it seems to me like it should be:

                        if (substr($splitGroup, 0, 3) !== 'DC=') {
                            $grps[$splitGroup] = $splitGroup;
                        } else {
                            $grps[substr($splitGroup, '3')] = substr($splitGroup, '3');
                        }
    

    Unless, again, this is just a quirk with our IT dept's set up.

    Thanks.

    opened by goobadaddy 3
  • Login via another username field

    Login via another username field

    Hi, thanks for your work! I failed with changing the username_field (my database attribute is different).

    In the retrieveByCredentials function you are using $credentials[$this->getUsernameField()] which is correct. In validateCredentials you are using hardcoded username authenticate($credentials['username'], $credentials['password'])

    BR

    opened by cromeis 2
  • ErrorException in LdapAuthUserProvider.php line 257: Undefined offset: 1

    ErrorException in LdapAuthUserProvider.php line 257: Undefined offset: 1

    I'm getting this after calling \Auth::validate(), when I have 'recursive_groups' => true,

    if (\Auth::validate(['username' => $input['username'], 'password' => $input['password']])) {
        // Authentication passed...
        return redirect()->intended('home');
    }
    
    opened by elite123 2
  • Switching from adldap/adldap to Adldap2/Adldap2

    Switching from adldap/adldap to Adldap2/Adldap2

    I'm going to switch the dependency to the new Adldap2/Adldap2 repository after it hits stable. It's the modern version of the original adldap/adldap. It's even possible that the changes getting merged to the original repository.

    opened by strebl 2
  • How do I access userlist?

    How do I access userlist?

    Thank you for this service. I have it setup and working fine with ldap, however I cannot figure out how to access the ldap userlist. Could you explain how I can grab it via one of my controllers?

    According to the inline comments, it is suppose to have all the data in Auth::user(). However I have dd that out and couldn't see any userList and when I do Auth::user()->userList, I get null.

    Honestly I just want the ability to check against the list of users in ldap and ensure my userlist is up-to-date. And if not, add any missing users.

    opened by shawndibble 1
  • Project abandoned?

    Project abandoned?

    Hi!,

    Why composer says: "Package strebl/adldap is abandoned, you should avoid using it. Use adldap2/adldap2 instead", after install.

    Specs:

    • Laravel 5.1
    • Composer: "strebl/l5-ldap-auth": "2.1.*"
    opened by rotrer 1
  • Switch to Adldap2/Adldap2-laravel!

    Switch to Adldap2/Adldap2-laravel!

    Please consider to switch to a new package: Adldap2/Adldap2-laravel.

    @stevebauman does a fantastic job over there. He first rewrote Adldap and now he wrote an Laravel driver.

    There are 3 major reasons to switch to Adldap2-laravel.

    • @stevebauman is a great maintainer, answering questions way faster than me.
    • Adldap2/Adldap2-laravel depends on the new and maintained Adldap2/Adldap2 package.
    • @stevebauman has way more experience than I have.

    Therefore I really recommend you to switch to this package.

    Unfortunately I didn't test it so far. But as far as I see, the package does the same, but even better.

    I won't stop maintaining this fork just yet, but I won't do anything big with it either. Therefore I closed #8, because there is no need to have two packages doing the same if one is so much better :smile:

    opened by strebl 2
  • Login Issue/request

    Login Issue/request

    This is not so much an issue as much as trying to reach out to get information. I am currently using this package on my site but I need to add a failover section, where if the user does not exist in the LDAP to check a mysql database for the login information. Can someone point me in the right direction.

    opened by likeadeckofcards 1
  • Remember Token

    Remember Token

    Hi - First thanks for your work on this. I've attempted to roll my own L5 ldap driver with varying degrees of success and this makes things much simpler.

    I have a question regarding the 'remember token'. The LdapAuthUserProvider->retrieveByToken() method has a comment saying "this shouldn't bee needed as user / password is in ldap". However, I still feel there is a need to store a token in the database for when the user wants to automatically be logged in next time. Without storing it somewhere the user will not have the ability to 'remember me'. It seems this would be easy enough, but there may be a reason why it has not been implemented. I want to be sure I am using this the way it was intended and not recreate the wheel.

    Any insights would be appreciated. Thanks again for your work on this.

    opened by darthtaco 1
  • Problem with laravel 5.1

    Problem with laravel 5.1

    I get this error: ErrorException in LdapAuthUserProvider.php line 117: Undefined index: fieldname

    my files

    config/auth.php

    <?php
    return [
            'driver' => 'ldap',
            'model' => App\User::class,
            'table' => 'users',
    
            'fields' => [
        'username' => 'samaccountname',
        'name' => 'displayName',
        'firstname' => 'givenName',
        'lastname' => 'sn',
        'groups' => 'memberOf',
    ],
    
    
        'password' => [
            'email' => 'emails.password',
            'table' => 'password_resets',
            'expire' => 60,
        ],
    
    ];
    

    config/adlap.php

    return [
        'account_suffix' => "@inge.local",
        'domain_controllers' => array("172.25.1.50", "172.25.1.51"), 
        'base_dn' => 'DC=ingeo,DC=local',
    ];
    
    
    //form login
    <form class="form-horizontal" role="form" method="POST" action="{{ url('/auth/login') }}">
    <input type="email" class="form-control" name="email" value="{{ old('email') }}">
    <input type="password" class="form-control" name="password">
    <button type="submit" class="btn btn-primary">Iniciar Sesión</button>
    </form>
    

    /routes.php Route::get('auth/login', 'Auth\AuthController@getLogin'); Route::post('auth/login', ['as' =>'auth/login', 'uses' => 'Auth\AuthController@postLogin']);

    //AuthController.php

    <?php
    
    namespace App\Http\Controllers\Auth;
    
    use App\User;
    use Validator;
    use App\Http\Controllers\Controller;
    use Illuminate\Foundation\Auth\ThrottlesLogins;
    use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
    
    class AuthController extends Controller
    {
        /*
        |--------------------------------------------------------------------------
        | Registration & Login Controller
        |--------------------------------------------------------------------------
        |
        | This controller handles the registration of new users, as well as the
        | authentication of existing users. By default, this controller uses
        | a simple trait to add these behaviors. Why don't you explore it?
        |
        */
    
        use AuthenticatesAndRegistersUsers, ThrottlesLogins;
    
        /**
         * Create a new authentication controller instance.
         *
         * @return void
         */
        public function __construct()
        {
            $this->middleware('guest', ['except' => 'getLogout']);
        }
    
        /**
         * Get a validator for an incoming registration request.
         *
         * @param  array  $data
         * @return \Illuminate\Contracts\Validation\Validator
         */
        protected function validator(array $data)
        {
            return Validator::make($data, [
                'name' => 'required|max:255',
                'email' => 'required|email|max:255|unique:users',
                'password' => 'required|confirmed|min:6',
            ]);
        }
    
        /**
         * Create a new user instance after a valid registration.
         *
         * @param  array  $data
         * @return User
         */
        protected function create(array $data)
        {
            return User::create([
                'name' => $data['name'],
                'email' => $data['email'],
                'password' => bcrypt($data['password']),
            ]);
        }
    }
    

    I do wrong?

    opened by montes2012 5
Releases(v2.1.3)
Owner
Manuel Strebel
Manuel Strebel
Simple readonly LDAP authentication with Laravel 5.2

ldap-auth Very basic READ ONLY LDAP authentication driver for Laravel 5.2+ Look HERE for the package for Laravel 5.1. However, only the 5.2 Version wi

Stan 26 Jun 20, 2021
It's a Laravel 8 authentication markdown that will help you to understand and grasp all the underlying functionality for Session and API Authentication

About Auth Starter It's a Laravel 8 authentication markdown that will help you to understand and grasp all the underlying functionality for Session an

Sami Alateya 10 Aug 3, 2022
Rinvex Authy is a simple wrapper for @Authy TOTP API, the best rated Two-Factor Authentication service for consumers, simplest 2fa Rest API for developers and a strong authentication platform for the enterprise.

Rinvex Authy Rinvex Authy is a simple wrapper for Authy TOTP API, the best rated Two-Factor Authentication service for consumers, simplest 2fa Rest AP

Rinvex 34 Feb 14, 2022
phpCAS is an authentication library that allows PHP applications to easily authenticate users via a Central Authentication Service (CAS) server.

phpCAS is an authentication library that allows PHP applications to easily authenticate users via a Central Authentication Service (CAS) server.

Apereo Foundation 780 Dec 24, 2022
A flexible, driver based Acl package for PHP 5.4+

Lock - Acl for PHP 5.4+ I'm sad to say that Lock is currently not maintained. I won't be able to offer support or accept new contributions for the cur

Beatswitch 892 Dec 30, 2022
:octocat: Socialite is an OAuth2 Authentication tool. It is inspired by laravel/socialite, you can easily use it without Laravel.

Socialite Socialite is an OAuth2 Authentication tool. It is inspired by laravel/socialite, You can easily use it in any PHP project. 中文文档 This tool no

安正超 1.2k Dec 22, 2022
A Simple method to create laravel authentication for an existing laravel project.

Laravel Simple Auth A Simple method to create laravel authentication for an existing laravel project. Indroduction Why I created this kind of package?

Dasun Tharanga 10 Dec 14, 2021
Laravel Auth is a Complete Build of Laravel 8 with Email Registration Verification, Social Authentication, User Roles and Permissions, User Profiles, and Admin restricted user management system.

Laravel Auth is a Complete Build of Laravel 8 with Email Registration Verification, Social Authentication, User Roles and Permissions, User Profiles, and Admin restricted user management system. Built on Bootstrap 4.

Jeremy Kenedy 2.8k Dec 31, 2022
🔐 JSON Web Token Authentication for Laravel & Lumen

Documentation Documentation for 1.* here For version 0.5.* See the WIKI for documentation. Supported by Auth0 If you want to easily add secure authent

Sean Tymon 10.7k Dec 31, 2022
Library to manage HTTP authentication with PHP. Includes ServiceProviders for easy Laravel integration.

Intervention HttpAuth Library to manage HTTP authentication with PHP. Includes ServiceProviders for easy Laravel integration. Installation You can ins

null 69 Jul 14, 2022
Minimal Laravel authentication scaffolding with Blade and Tailwind.

Introduction Breeze provides a minimal and simple starting point for building a Laravel application with authentication. Styled with Tailwind, Breeze

The Laravel Framework 2.1k Jan 3, 2023
User Authentication Managment With Laravel 8

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

null 17 Jul 17, 2022
Confide is a authentication solution for Laravel 4

Confide (A Laravel4 Package) Confide is an authentication solution for Laravel made to cut repetitive work involving the management of users. A DRY ap

Zizaco 1.2k Dec 30, 2022
Laravel passport authentication API endpoints

Basic sample code for Laravel/Passport to authenticate users via API

Devdreamsolution 2 Oct 19, 2021
🔐 JSON Web Token Authentication for Laravel & Lumen

Credits This repository it a fork from original tymonsdesigns/jwt-auth, we decided to fork and work independent because the original one was not being

null 490 Dec 27, 2022
Laravel Sanctum provides a featherweight authentication system for SPAs and simple APIs.

Introduction Laravel Sanctum provides a featherweight authentication system for SPAs and simple APIs. Official Documentation Documentation for Sanctum

The Laravel Framework 2.4k Dec 30, 2022
Backend controllers and scaffolding for Laravel authentication.

Introduction Laravel Fortify is a frontend agnostic authentication backend for Laravel. Fortify powers the registration, authentication, and two-facto

The Laravel Framework 1.4k Dec 20, 2022
Social OAuth Authentication for Laravel 5. drivers: facebook, github, google, linkedin, weibo, qq, wechat and douban

Social OAuth Authentication for Laravel 5. drivers: facebook, github, google, linkedin, weibo, qq, wechat and douban

安正超 330 Nov 14, 2022
Laravel JWT-Authentication API starter kit for rapid backend prototyping.

Laravel JWT API A Laravel JWT API starter kit. Features Laravel 8 Login, register, email verification and password reset Authentication with JWT Socia

Oybek Odilov 3 Nov 6, 2022