You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/0 - install.md
+51-13Lines changed: 51 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,23 +1,23 @@
1
-
# Installation
1
+
# Installation
2
2
3
-
Installation is done through [Composer](https://getcomposer.org). The example assumes you have it installed globally.
3
+
Installation is done through [Composer](https://getcomposer.org). The example assumes you have it installed globally.
4
4
If you have it installed as a phar, or othewise you will need to adjust the way you call composer itself.
5
5
6
6
```
7
7
> composer require codeigniter4/shield
8
8
```
9
9
10
10
This requires the [CodeIgniter Settings](https://github.com/codeigniter4/settings) package, which uses a database
11
-
table to store configuration options. As such, you should run the migrations.
11
+
table to store configuration options. As such, you should run the migrations.
12
12
13
13
```
14
14
> php spark migrate --all
15
15
```
16
16
17
17
## Initial Setup
18
18
19
-
There are a few setup items to do before you can start using Shield in
20
-
your project.
19
+
There are a few setup items to do before you can start using Shield in
20
+
your project.
21
21
22
22
1. Copy the `Auth.php` and `AuthGroups.php` from `vendor/codeigniter4/shield/src/Config/` into your project's config folder and update the namespace to `Config`. You will also need to have these classes extend the original classes. See the example below. These files contain all of the settings, group, and permission information for your application and will need to be modified to meet the needs of your site.
23
23
@@ -38,7 +38,7 @@ class Auth extends ShieldAuth
38
38
}
39
39
```
40
40
41
-
2.**Helper Setup** The `auth` and `setting` helpers need to be included in almost every page. The simplest way to do this is to add them to the `BaseController::initController` method:
41
+
2.**Helper Setup** The `auth` and `setting` helpers need to be included in almost every page. The simplest way to do this is to add them to the `BaseController::initController` method:
42
42
43
43
```php
44
44
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
@@ -52,14 +52,14 @@ public function initController(RequestInterface $request, ResponseInterface $res
52
52
53
53
This requires that all of your controllers extend the `BaseController`, but that's a good practice anyway.
54
54
55
-
3.**Routes Setup** The default auth routes can be setup with a single call in `app/Config/Routes.php`:
55
+
3.**Routes Setup** The default auth routes can be setup with a single call in `app/Config/Routes.php`:
56
56
57
57
```php
58
58
service('auth')->routes($routes);
59
59
```
60
60
61
61
4. (If you are running CodeIgniter v4.2.0 or higher you can skip this step). Add the new password validation rules
62
-
by editing `app/Config/Validation.php`:
62
+
by editing `app/Config/Validation.php`:
63
63
64
64
```php
65
65
use CodeIgniter\Shield\Authentication\Passwords\ValidationRules as PasswordRules;
@@ -73,6 +73,44 @@ public $ruleSets = [
73
73
];
74
74
```
75
75
76
+
## Controller Filters
77
+
78
+
Shield provides 3 [Controller Filters](https://codeigniter.com/user_guide/incoming/filters.html) you can
79
+
use to protect your routes, `session`, `tokens`, and `chained`. The first two cover the `Session` and
80
+
`AccessTokens` authenticators, respectively. The `chained` filter will check both authenticators in sequence
81
+
to see if the user is logged in through either of authenticators, allowing a single API endpoint to
82
+
work for both an SPA using session auth, and a mobile app using access tokens.
83
+
84
+
These filters are already loaded for you by the registrar class located at `src/Config/Registrar.php`.
Shield has the following controllers that can be extended to handle
96
-
various parts of the authentication process:
133
+
Shield has the following controllers that can be extended to handle
134
+
various parts of the authentication process:
97
135
98
-
- **ActionController** handles the after login and after-registration actions that can be ran, like Two Factor Authentication and Email Verification.
136
+
- **ActionController** handles the after login and after-registration actions that can be ran, like Two Factor Authentication and Email Verification.
99
137
100
138
- **LoginController** handles the login process.
101
139
@@ -105,7 +143,7 @@ various parts of the authentication process:
105
143
override the message that is displayed to a user to describe what is happening, if you'd like to provide more information than simply swapping out the view used.
106
144
107
145
It is not recommended to copy the entire controller into app and change it's namespace. Instead, you should create a new controller that extends
108
-
the existing controller and then only override the methods needed. This allows the other methods to always stay up to date with any security
146
+
the existing controller and then only override the methods needed. This allows the other methods to always stay up to date with any security
109
147
updates that might happen in the controllers.
110
148
111
149
```php
@@ -119,7 +157,7 @@ class LoginController extends ShieldLogin
During authentication, the token the user used is stored on the user. Once authenticated, you
262
+
During authentication, the token the user used is stored on the user. Once authenticated, you
263
263
can use the `tokenCan()` and `tokenCant()` methods on the user to determine if they have access
264
264
to the specified scope.
265
265
@@ -272,23 +272,3 @@ if ($user->tokenCant('forums.manage')) {
272
272
// do something....
273
273
}
274
274
```
275
-
276
-
## Controller Filters
277
-
278
-
Shield provides 3 [Controller Filters](https://codeigniter.com/user_guide/incoming/filters.html) you can
279
-
use to protect your routes, `session`, `tokens`, and `chained`. The first two cover the `Session` and `AccessTokens` authenticators, respectively. The `chained` filter will check both authenticators in sequence
280
-
to see if the user is logged in through either of authenticators, allowing a single API endpoint to
281
-
work for both an SPA using session auth, and a mobile app using access tokens.
282
-
283
-
These filters are already loaded for you by the registrar class located at `src/Config/Registrar.php`.
0 commit comments