Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Commit a2ef8f5

Browse files
committed
Updated readme
1 parent 0de6012 commit a2ef8f5

File tree

1 file changed

+49
-67
lines changed

1 file changed

+49
-67
lines changed

readme.md

Lines changed: 49 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Adldap2 - Laravel allows easy configuration, access, management and authenticati
3636
Insert Adldap2-Laravel into your `composer.json` file:
3737

3838
```json
39-
"adldap2/adldap2-laravel": "2.1.*",
39+
"adldap2/adldap2-laravel": "3.0.*",
4040
```
4141

4242
Or via command line:
@@ -74,7 +74,7 @@ $user = Adldap::search()->users()->find('john doe');
7474
// Searching for a user.
7575
$search = Adldap::search()->where('cn', '=', 'John Doe')->get();
7676

77-
// Authenticating.
77+
// Authenticating against your LDAP server.
7878
if (Adldap::auth()->attempt($username, $password)) {
7979
// Passed!
8080
}
@@ -91,6 +91,7 @@ $user->save();
9191
```
9292

9393
Or you can inject the Adldap contract:
94+
9495
```php
9596
use Adldap\Contracts\AdldapInterface;
9697

@@ -118,7 +119,7 @@ class UserController extends Controller
118119
*/
119120
public function index()
120121
{
121-
$users = $this->adldap->getDefaultProvider()->search()->users()->get();
122+
$users = $this->adldap->search()->users()->get();
122123

123124
return view('users.index', compact('users'));
124125
}
@@ -188,16 +189,52 @@ Change the `driver` value inside the `users` authentication provider to `adldap`
188189

189190
### Usage
190191

191-
#### Username Attributes
192+
#### Usernames
193+
194+
Inside your `config/adldap_auth.php` file there is a configuration option named `usernames`.
195+
196+
This array contains the `ldap` attribute you use for authenticating users, as well
197+
as the `eloquent` attribute for locating the LDAP users model.
198+
199+
```php
200+
201+
'usernames' => [
202+
203+
'ldap' => 'userprincipalname',
204+
205+
'eloquent' => 'email',
206+
207+
],
208+
```
209+
210+
If you're using a `username` field instead of `email` in your application, you will need to change this configuration.
211+
212+
> **Note**: Keep in mind you will also need to update your `database/migrations/2014_10_12_000000_create_users_table.php`
213+
> migration to use a username field instead of email, **as well as** your LoginController.
192214
193-
Inside your `config/adldap_auth.php` file there is a configuration option named `username_attribute`. The key of the
194-
array indicates the input name of your login form, and the value indicates the LDAP attribute that this references.
215+
For example, if you'd like to login users by their `samaccountname`:
216+
217+
```php
218+
219+
'usernames' => [
220+
221+
'ldap' => 'samaccountname',
222+
223+
'eloquent' => 'username',
224+
225+
],
226+
```
227+
228+
Be sure to update the `sync_attributes` option to synchronize the users `username` as well:
229+
230+
```php
231+
'sync_attributes' => [
195232

196-
This option just allows you to set your input name to however you see fit, and allow different ways of logging in a user.
233+
'username' => 'samaccountname', // Changed from 'email' => 'userprincipalname'
234+
'name' => 'cn',
197235

198-
> **Note**: The actual authentication against your AD server is done with
199-
> the `login_attribute` inside your `config/adldap_auth.php` file. The
200-
> `username_attribute` array is used for **locating** your user in AD.
236+
],
237+
```
201238

202239
#### Logging In
203240

@@ -223,61 +260,6 @@ public function login(Request $request)
223260
}
224261
```
225262

226-
##### Logging in Users Via Their Username
227-
228-
If you need to login users via their username (`samaccountname`), then you'll need to modify a couple things.
229-
Otherwise, if you're logging in users via email, then you don't need to change a thing and you can
230-
skip over the following documentation.
231-
232-
First make sure you have the `username` field inside your users database table as well.
233-
By default, laravel's migrations use the `email` field:
234-
235-
```php
236-
// 2014_10_12_000000_create_users_table.php
237-
Schema::create('users', function (Blueprint $table) {
238-
$table->increments('id');
239-
$table->string('name');
240-
241-
// Changed to `username` instead of `email`.
242-
$table->string('username')->unique();
243-
244-
$table->string('password');
245-
$table->rememberToken();
246-
$table->timestamps();
247-
$table->softDeletes();
248-
});
249-
```
250-
251-
Inside `config/adldap_auth.php`, change the array to the following:
252-
253-
```php
254-
'username_attribute' => ['username' => 'samaccountname'],
255-
```
256-
257-
In your login form, change the username form input name to your configured
258-
input name (by default this is set to `email`):
259-
260-
```html
261-
<!-- Changed the `name` attribute to `username`. -->
262-
<input type="text" name="username" />
263-
```
264-
265-
You'll also need to add the following to your AuthController / LoginController if
266-
you're not already overriding the default postLogin method:
267-
268-
```php
269-
// In Laravel <= 5.2
270-
protected $username = 'username';
271-
272-
// In Laravel >= 5.3
273-
public function username()
274-
{
275-
return 'username';
276-
}
277-
```
278-
279-
Once you've followed these steps, you'll be able to authenticate LDAP users by their username instead of their email.
280-
281263
## Features
282264

283265
#### Synchronizing Attributes
@@ -303,7 +285,7 @@ use an attribute handler class to sync your model attributes manually. For examp
303285
```php
304286
'sync_attributes' => [
305287

306-
\App\Handlers\LdapAttributeHandler::class,
288+
App\Handlers\LdapAttributeHandler::class,
307289

308290
],
309291
```
@@ -383,7 +365,7 @@ active directory authentication fails. This option would be handy in environment
383365
- You may have some active directory users and other users registering through the website itself (user does not exist in your AD).
384366
- Local development where your AD server may be unavailable
385367

386-
To enable it, simply set the option to true in your `adldap_auth.php` configuration file:
368+
To enable it, simply set the option to true in your `config/adldap_auth.php` configuration file:
387369

388370
```php
389371
'login_fallback' => false, // Set to true.

0 commit comments

Comments
 (0)