Here is a step by step guide for configuring Adldap2 with a fresh new laravel project. This guide assumes you have knowledge working with Laravel, Active Directory, LDAP Protocol and command line tools (such as Composer and Artisan).
This guide is thanks to @st-claude.
-
Create a new laravel project by running
laravel new my-apporcomposer create-project --prefer-dist laravel/laravel my-app. Laravel Installation -
Insert
"adldap2/adldap2-laravel": "2.0.*"in yourcomposer.jsonfile in the root directory of your project. -
Run the
composer updatecommand in the root directory of your project to pull in Adldap2 and its dependencies. -
Create a new database in your desired database interface (such as PhpMyAdmin, MySQL Workbench etc.)
-
Enter your database details and credentials inside the
.envfile located in your project root directory (if there is not one there, rename the.env.exampleto.env). -
If you're using Active Directory username's to login users instead of their emails, you will need to change the default
emailcolumn indatabase/migrations/2014_10_12_000000_create_users_table.php.// database/migrations/2014_10_12_000000_create_users_table.php Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('name'); // From: $table->string('email')->unique(); // To: $table->string('username')->unique(); $table->string('password'); $table->rememberToken(); $table->timestamps();
});
7. Now run `php artisan migrate`.
8. Insert the following service providers in your `config/app.php` file (in the `providers` property):
```php
Adldap\Laravel\AdldapServiceProvider::class,
Adldap\Laravel\AdldapAuthServiceProvider::class,
-
Now, insert the facade into your
config/app.phpfile:'Adldap' => Adldap\Laravel\Facades\Adldap::class,
Note: Insertion of the facade in your
app.phpfile isn't necessary unless you're planning on utilizing it. -
Now run
php artisan vendor:publishto publish Adldap2's configuration files.- Two files will be published inside your
configfolder,adldap.phpandadldap_auth.php.
- Two files will be published inside your
-
Modify the
config/adldap.phpfile for your AD server configuration. -
Run the command
php artisan make:authto scaffold authentication controllers and routes. -
Inside the generated
app/Http/Controllers/Auth/AuthController.php, you'll need to add theprotected $usernameproperty if you're logging in users by username. Otherwise ignore this step.class AuthController extends Controller { protected $username = 'username';
-
Now insert a new auth driver inside your
config/auth.phpfile:'guards' => [ 'web' => [ 'driver' => 'session', 'provider' => 'adldap', // Switched to 'adldap' ], 'api' => [ 'driver' => 'token', 'provider' => 'users', ], ], 'providers' => [ // New 'adldap' provider: 'adldap' => [ 'driver' => 'adldap', 'model' => App\User::class, ], 'users' => [ 'driver' => 'eloquent', 'model' => App\User::class, ], ],
-
Inside your
resources/views/auth/login.blade.phpfile, if you're requiring the user logging in by username, you'll need to modify the HTML input tousernameinstead ofemail. Ignore this step otherwise.From:
<input type="email" class="form-control" name="email" value="{{ old('email') }}">
To:
<input type="text" class="form-control" name="username" value="{{ old('username') }}">
-
You should now be able to login to your Laravel application using LDAP authentication!