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/authorization.md
+25-1Lines changed: 25 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,8 @@
9
9
-[can()](#can)
10
10
-[inGroup()](#ingroup)
11
11
-[hasPermission()](#haspermission)
12
+
-[Authorizing via Filters](#authorizing-via-filters)
13
+
-[Authorizing via Routes](#authorizing-via-routes)
12
14
-[Managing User Permissions](#managing-user-permissions)
13
15
-[addPermission()](#addpermission)
14
16
-[removePermission()](#removepermission)
@@ -128,6 +130,28 @@ if (! $user->hasPermission('users.create')) {
128
130
}
129
131
```
130
132
133
+
#### Authorizing via Filters
134
+
135
+
You can restrict access to multiple routes through a [Controller Filter](https://codeigniter.com/user_guide/incoming/filters.html). One is provided for both restricting via groups the user belongs to, as well as which permission they need. The filters are automatically registered with the system under the `group` and `permission` aliases, respectively. You can define the protections within `app/Config/Filters.php`:
session and tokens | The `Session` and `AccessTokens` authenticators, respectively.
155
+
chained | The filter will check both authenticators in sequence to see if the user is logged in through either of authenticators, allowing a single API endpoint to work for both an SPA using session auth, and a mobile app using access tokens.
156
+
auth-rates | Provides a good basis for rate limiting of auth-related routes.
157
+
group | Checks if the user is in one of the groups passed in.
158
+
permission | Checks if the user has the passed permissions.
138
159
139
-
Shield provides 4 [Controller Filters](https://codeigniter.com/user_guide/incoming/filters.html) you can
140
-
use to protect your routes, `session`, `tokens`, and `chained`. The first two cover the `Session` and
141
-
`AccessTokens` authenticators, respectively. The `chained` filter will check both authenticators in sequence
142
-
to see if the user is logged in through either of authenticators, allowing a single API endpoint to
143
-
work for both an SPA using session auth, and a mobile app using access tokens. The fourth, `auth-rates`,
144
-
provides a good basis for rate limiting of auth-related routes.
145
160
These can be used in any of the [normal filter config settings](https://codeigniter.com/user_guide/incoming/filters.html?highlight=filter#globals), or [within the routes file](https://codeigniter.com/user_guide/incoming/routing.html?highlight=routs#applying-filters).
146
161
162
+
> **Note** These filters are already loaded for you by the registrar class located at `src/Config/Registrar.php`.
163
+
147
164
### Protect All Pages
148
165
149
166
If you want to limit all routes (e.g. `localhost:8080/admin`, `localhost:8080/panel` and ...), you need to add the following code in the `app/Config/Filters.php` file.
@@ -158,18 +175,6 @@ public $globals = [
158
175
];
159
176
```
160
177
161
-
> **Note** These filters are already loaded for you by the registrar class located at `src/Config/Registrar.php`.
0 commit comments