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-app
orcomposer create-project --prefer-dist laravel/laravel my-app
. Laravel Installation -
Insert
"adldap2/adldap2-laravel": "2.0.*"
in yourcomposer.json
file in the root directory of your project. -
Run the
composer update
command 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
.env
file located in your project root directory (if there is not one there, rename the.env.example
to.env
). -
If you're using Active Directory username's to login users instead of their emails, you will need to change the default
email
column 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.php
file:'Adldap' => Adldap\Laravel\Facades\Adldap::class,
Note: Insertion of the facade in your
app.php
file isn't necessary unless you're planning on utilizing it. -
Now run
php artisan vendor:publish
to publish Adldap2's configuration files.- Two files will be published inside your
config
folder,adldap.php
andadldap_auth.php
.
- Two files will be published inside your
-
Modify the
config/adldap.php
file for your AD server configuration. -
Run the command
php artisan make:auth
to scaffold authentication controllers and routes. -
Inside the generated
app/Http/Controllers/Auth/AuthController.php
, you'll need to add theprotected $username
property 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.php
file:'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.php
file, if you're requiring the user logging in by username, you'll need to modify the HTML input tousername
instead 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!