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

Commit 497611b

Browse files
committed
Move auth installation to separate readme
1 parent 38de0cf commit 497611b

File tree

2 files changed

+133
-134
lines changed

2 files changed

+133
-134
lines changed

docs/auth/installation.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Auth Driver
2+
3+
The Adldap Laravel auth driver allows you to seamlessly authenticate AD users,
4+
as well as have a local database record of the user.
5+
6+
This allows you to easily attach information to the users account
7+
as you would a regular laravel application.
8+
9+
> **Note**: The Adldap auth driver actually extends from and utilizes Laravel's eloquent auth driver.
10+
11+
## Installation
12+
13+
### Laravel 5.1
14+
15+
Insert the `AdldapAuthServiceProvider` into your `config/app.php` file:
16+
17+
```php
18+
Adldap\Laravel\AdldapAuthServiceProvider::class,
19+
```
20+
21+
Publish the auth configuration:
22+
23+
```bash
24+
php artisan vendor:publish --tag="adldap"
25+
```
26+
27+
Change the auth driver in `config/auth.php` to `adldap`:
28+
29+
```php
30+
'driver' => 'adldap',
31+
```
32+
33+
### Laravel 5.2 & Up
34+
35+
Insert the `AdldapAuthServiceProvider` into your `config/app.php` file:
36+
37+
```php
38+
Adldap\Laravel\AdldapAuthServiceProvider::class,
39+
```
40+
41+
Publish the auth configuration:
42+
43+
```bash
44+
php artisan vendor:publish --tag="adldap"
45+
```
46+
47+
Open your `config/auth.php` configuration file and change the following:
48+
49+
Change the `driver` value inside the `users` authentication provider to `adldap`:
50+
51+
```php
52+
'providers' => [
53+
'users' => [
54+
'driver' => 'adldap', // Changed from 'eloquent'
55+
'model' => App\User::class,
56+
],
57+
],
58+
```
59+
60+
61+
## Basic Setup
62+
63+
### Usernames
64+
65+
Inside your `config/adldap_auth.php` file there is a configuration option named `usernames`.
66+
67+
This array contains the `ldap` attribute you use for authenticating users, as well
68+
as the `eloquent` attribute for locating the LDAP users model.
69+
70+
```php
71+
72+
'usernames' => [
73+
74+
'ldap' => 'userprincipalname',
75+
76+
'eloquent' => 'email',
77+
78+
],
79+
```
80+
81+
If you're using a `username` field instead of `email` in your application, you will need to change this configuration.
82+
83+
> **Note**: Keep in mind you will also need to update your `database/migrations/2014_10_12_000000_create_users_table.php`
84+
> migration to use a username field instead of email, **as well as** your LoginController.
85+
86+
For example, if you'd like to login users by their `samaccountname`:
87+
88+
```php
89+
90+
'usernames' => [
91+
92+
'ldap' => 'samaccountname',
93+
94+
'eloquent' => 'username',
95+
96+
],
97+
```
98+
99+
Be sure to update the `sync_attributes` option to synchronize the users `username` as well:
100+
101+
```php
102+
'sync_attributes' => [
103+
104+
'username' => 'samaccountname', // Changed from 'email' => 'userprincipalname'
105+
'name' => 'cn',
106+
107+
],
108+
```
109+
110+
### Logging In
111+
112+
Login a user regularly using `Auth::attempt($credentials);`.
113+
114+
Once a user is authenticated, retrieve them as you would regularly:
115+
116+
```php
117+
public function login(Request $request)
118+
{
119+
if (Auth::attempt($request->only(['email', 'password'])) {
120+
121+
// Returns \App\User model configured in `config/auth.php`.
122+
$user = Auth::user();
123+
124+
125+
return redirect()->to('home')
126+
->withMessage('Logged in!');
127+
}
128+
129+
return redirect()->to('login')
130+
->withMessage('Hmm... Your username or password is incorrect');
131+
}
132+
```

readme.md

Lines changed: 1 addition & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Adldap2 - Laravel allows easy configuration, access, management and authenticati
1717
* [Installation](#installation)
1818
* [Usage](#usage)
1919
* [Auth Driver](#auth-driver)
20+
* [Quick Start - From Scratch](docs/quick-start.md)
2021
* [Installation](#installation-1)
2122
* [Setup](#setup)
2223
* Features
@@ -31,8 +32,6 @@ Adldap2 - Laravel allows easy configuration, access, management and authenticati
3132

3233
## Installation
3334

34-
[Quick Start - From Scratch](docs/quick-start.md)
35-
3635
Insert Adldap2-Laravel into your `composer.json` file:
3736

3837
```json
@@ -127,135 +126,3 @@ class UserController extends Controller
127126
```
128127

129128
To see more usage in detail, please visit the [Adldap2 Repository](http://github.com/Adldap2/Adldap2);
130-
131-
## Auth Driver
132-
133-
The Adldap Laravel auth driver allows you to seamlessly authenticate AD users,
134-
as well as have a local database record of the user.
135-
136-
This allows you to easily attach information to the users account
137-
as you would a regular laravel application.
138-
139-
> **Note**: The Adldap auth driver actually extends from and utilizes Laravel's eloquent auth driver.
140-
141-
### Installation
142-
143-
#### Laravel 5.1
144-
145-
Insert the `AdldapAuthServiceProvider` into your `config/app.php` file:
146-
147-
```php
148-
Adldap\Laravel\AdldapAuthServiceProvider::class,
149-
```
150-
151-
Publish the auth configuration:
152-
153-
```bash
154-
php artisan vendor:publish --tag="adldap"
155-
```
156-
157-
Change the auth driver in `config/auth.php` to `adldap`:
158-
159-
```php
160-
'driver' => 'adldap',
161-
```
162-
163-
#### Laravel 5.2 & Up
164-
165-
Insert the `AdldapAuthServiceProvider` into your `config/app.php` file:
166-
167-
```php
168-
Adldap\Laravel\AdldapAuthServiceProvider::class,
169-
```
170-
171-
Publish the auth configuration:
172-
173-
```bash
174-
php artisan vendor:publish --tag="adldap"
175-
```
176-
177-
Open your `config/auth.php` configuration file and change the following:
178-
179-
Change the `driver` value inside the `users` authentication provider to `adldap`:
180-
181-
```php
182-
'providers' => [
183-
'users' => [
184-
'driver' => 'adldap', // Changed from 'eloquent'
185-
'model' => App\User::class,
186-
],
187-
],
188-
```
189-
190-
### Setup
191-
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.
214-
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' => [
232-
233-
'username' => 'samaccountname', // Changed from 'email' => 'userprincipalname'
234-
'name' => 'cn',
235-
236-
],
237-
```
238-
239-
#### Logging In
240-
241-
Login a user regularly using `Auth::attempt($credentials);`.
242-
243-
Once a user is authenticated, retrieve them as you would regularly:
244-
245-
```php
246-
public function login(Request $request)
247-
{
248-
if (Auth::attempt($request->only(['email', 'password'])) {
249-
250-
// Returns \App\User model configured in `config/auth.php`.
251-
$user = Auth::user();
252-
253-
254-
return redirect()->to('home')
255-
->withMessage('Logged in!');
256-
}
257-
258-
return redirect()->to('login')
259-
->withMessage('Hmm... Your username or password is incorrect');
260-
}
261-
```

0 commit comments

Comments
 (0)