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

Commit b896b4c

Browse files
committed
More setup documentation
1 parent 0e696f8 commit b896b4c

File tree

1 file changed

+46
-9
lines changed

1 file changed

+46
-9
lines changed

docs/auth/setup.md

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,7 @@ All other users will be denied authentication, even if their credentials are val
271271
272272
## Usernames
273273

274-
Inside your `config/ldap_auth.php` file there is a configuration option named `usernames`.
275-
276-
This array contains the `ldap` attributes you use for authenticating users, as well as the `eloquent` attribute for locating the LDAP users local model.
277-
278-
You can ignore the `windows` configuration array, unless you're planning on using the included [middleware](middleware.md) for single sign on authentication.
274+
Inside your `config/ldap_auth.php` file there is a configuration option named `usernames`:
279275

280276
```php
281277
'usernames' => [
@@ -295,7 +291,51 @@ You can ignore the `windows` configuration array, unless you're planning on usin
295291
],
296292
```
297293

298-
If you're using a `username` field instead of `email` in your application, you will need to change this configuration.
294+
Let's go through each option with their meaning.
295+
296+
### LDAP
297+
298+
The LDAP array contains two elements each with a key and value.
299+
300+
The `discover` key contains the LDAP users attribute you would like your authenticating users to be located by.
301+
302+
> **Note**: If you're using the `NoDatabaseUserProvider` it is extremely important to know that this value is used as the key to retrieve the inputted username from the `Auth::attempt()` credentials array.
303+
>
304+
> For example, if you're executing an `Auth::attempt(['username' => 'jdoe..'])` and you have a `discover` value set to `userprincipalname` then the Adldap2-Laravel auth driver will try to retrieve your users username from the given credentials array with the key `userprincipalname`. This would generate an exception since this key does not exist in the above credentials array.
305+
306+
For example, executing the following:
307+
308+
```php
309+
Auth::attempt(['email' => 'jdoe@corp.com', 'password' => 'password'])
310+
```
311+
312+
Will perform an LDAP search for a user with the `userprincipalname` equal to `jdoe@corp.com`.
313+
314+
If you change `Auth::attempt()` `email` key, you will need to change the `eloquent` key to match.
315+
316+
The `authenticate` key contains the LDAP users attriubte you would like to perform LDAP authentication on.
317+
318+
For example, executing the following:
319+
320+
```php
321+
Auth::attempt(['email' => 'jdoe@corp.com', 'password' => 'password'])
322+
```
323+
324+
Will try to locate a user in your LDAP directory with a `userprincipalname` equal to `jdoe@corp.com`. Then, when an LDAP record of this user is located, their `disintinguishedname` will be retrieved from this record, an be passed into an `Adldap\Auth\Guard::attempt()` (ex `Guard::attempt('cn=John Doe,ou=Users,dc=corp,dc=com', 'password')`).
325+
326+
> **Note**: It's **extremely** important to know that your configured `account_suffix` and `account_prefix` (located in your `config/ldap.php` file) will be appended or prepended *onto* this passed in username.
327+
328+
You can ignore the `windows` configuration array, unless you're planning on using the included [middleware](middleware.md) for single sign on authentication.
329+
330+
### Eloquent
331+
332+
The eloquent key contains a value that should match the username column you have set up in your `users` database table.
333+
334+
For example, if you're using a `username` field instead of `email` in your application, you will need to change this option to `username`.
335+
336+
> **Note**: If you're using the `DatabaseUserProvider` it is extremely important to know that this value is used as the key to retrieve the inputted username from the `Auth::attempt()` credentials array.
337+
>
338+
> For example, if you're executing an `Auth::attempt(['username' => 'jdoe..'])` and you have an `eloquent` value set to `email` then the Adldap2-Laravel auth driver will try to retrieve your users username from the given credentials array with the key `email`. This would generate an exception since this key does not exist in the above credentials array.
299339
300340
> **Note**: Keep in mind you will also need to update your `database/migrations/2014_10_12_000000_create_users_table.php`
301341
> migration to use a username field instead of email, **as well as** your LoginController.
@@ -306,11 +346,8 @@ For example, if you'd like to login users by their `samaccountname`:
306346
'usernames' => [
307347

308348
'ldap' => [
309-
310349
'discover' => 'samaccountname', // Changed from `userprincipalname`
311-
312350
'authenticate' => 'distinguishedname',
313-
314351
],
315352

316353
'eloquent' => 'username', // Changed from `email`

0 commit comments

Comments
 (0)