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

Commit 9c13d5f

Browse files
committed
Added multiple connection authentication docs
1 parent 744567e commit 9c13d5f

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

README.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ It includes:
1616
- An Adldap contract (`Adldap\Contracts\Adldap`) for dependency injection through Laravel's IoC
1717
- An Auth driver for easily allowing users to login to your application using active directory
1818
- An Adldap facade (`Adldap\Laravel\Facades\Adldap`) for easily retrieving the Adldap instance from the IoC
19+
- Support for multiple LDAP connections
1920

2021
## Installation
2122

2223
Insert Adldap2-Laravel into your `composer.json` file:
2324

2425
```json
25-
"adldap2/adldap2-laravel": "1.4.*",
26+
"adldap2/adldap2-laravel": "v2.0.*",
2627
```
2728

2829
Then run `composer update`.
@@ -49,13 +50,13 @@ Now you're all set!
4950
You can perform all methods on Adldap through its facade like so:
5051
```php
5152
// Finding a user.
52-
$user = Adldap::users()->find('john doe');
53+
$user = Adldap::getProvider('default')->search()->users()->find('john doe');
5354

5455
// Searching for a user.
55-
$search = Adldap::search()->where('cn', '=', 'John Doe')->get();
56+
$search = Adldap::getProvider('default')->search()->where('cn', '=', 'John Doe')->get();
5657

5758
// Authenticating.
58-
if (Adldap::authenticate($username, $password)) {
59+
if (Adldap::getProvider('default')->auth()->attempt($username, $password)) {
5960
// Passed!
6061
}
6162
```
@@ -88,7 +89,7 @@ class UserController extends Controller
8889
*/
8990
public function index()
9091
{
91-
$users = $this->adldap->users()->all();
92+
$users = $this->adldap->getProvider('default')->search()->users()->get();
9293

9394
return view('users.index', compact('users'));
9495
}
@@ -401,3 +402,22 @@ To enable it, simply set the option to true in your `adldap_auth.php` configurat
401402
```php
402403
'login_fallback' => false, // Set to true.
403404
```
405+
406+
#### Multiple Authentication Connections
407+
408+
To swap connections on the fly, set your configurations default connection and try re-authenticating the user:
409+
410+
```php
411+
if (Auth::attempt($credentials)) {
412+
// Logged in successfully
413+
} else {
414+
// Login failed, swap and try other connection.
415+
Config::set('adldap_auth.connection', 'other-connection');
416+
417+
if (Auth::attempt($credentials)) {
418+
// Passed logging in with other connection.
419+
}
420+
}
421+
422+
return 'Login incorrect!';
423+
```

0 commit comments

Comments
 (0)