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
Including the plugin is pretty much as with every other CakePHP plugin:
116
+
117
+
### Required Dependencies
118
+
119
+
TinyAuth acts as a wrapper around CakePHP's official Authentication and Authorization plugins. You need to install them first:
120
+
121
+
```bash
122
+
# Required for authentication features
123
+
composer require cakephp/authentication
124
+
125
+
# Required for authorization features
126
+
composer require cakephp/authorization
127
+
```
128
+
129
+
Then install TinyAuth:
117
130
118
131
```bash
119
132
composer require dereuromark/cakephp-tinyauth
120
133
```
121
134
122
-
Then, to load the plugin:
135
+
Finally, load the plugin:
123
136
124
137
```sh
125
138
bin/cake plugin load TinyAuth
126
139
```
127
140
128
-
That's it. It should be up and running.
141
+
**Note:** The AuthUser component and helper can work standalone with any authentication solution. For the main TinyAuth.Authentication and TinyAuth.Authorization components, the official plugins are required dependencies.
Copy file name to clipboardExpand all lines: docs/Authorization.md
+34-50Lines changed: 34 additions & 50 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,9 @@
1
1
# TinyAuth Authorization
2
2
The fast and easy way for user authorization in CakePHP applications.
3
3
4
-
Enable TinyAuth Authorize if you want to add instant (and easy) role
4
+
**IMPORTANT:** This component wraps the official CakePHP Authorization plugin. You must install it first - see [AuthorizationPlugin.md](AuthorizationPlugin.md).
5
+
6
+
Enable TinyAuth Authorization if you want to add instant (and easy) INI-based role
5
7
based access control (RBAC) to your application.
6
8
7
9
## Basic Features
@@ -18,41 +20,23 @@ frontend yourself)
18
20
19
21
## Enabling
20
22
21
-
Assuming you already have authentication set up correctly you can enable
22
-
authorization in your controller's `beforeFilter()` method like this example:
23
+
**IMPORTANT:** You must first install and configure the official Authorization plugin. See [AuthorizationPlugin.md](AuthorizationPlugin.md) for complete setup instructions.
23
24
24
-
**DEPRECATED** Use middleware approach and `TinyAuth.Authorization` instead. Rest of the page is accurate.
25
+
Load the Authorization component in your controller:
25
26
26
27
```php
27
28
// src/Controller/AppController
28
29
29
30
public function initialize() {
30
31
parent::initialize();
31
32
32
-
$this->loadComponent('TinyAuth.Auth', [
33
-
'authorize' => [
34
-
'TinyAuth.Tiny' => [
35
-
...
36
-
],
37
-
...
38
-
]
33
+
$this->loadComponent('TinyAuth.Authorization', [
34
+
...
39
35
]);
40
36
}
41
37
```
42
-
TinyAuth Authorize can be used in combination with any [CakePHP Authentication Type](http://book.cakephp.org/3.0/en/controllers/components/authentication.html#choosing-an-authentication-type), as well.
43
38
44
-
45
-
Please note that `TinyAuth.Auth` replaces the default CakePHP `Auth` component. Do not try to load both at once.
46
-
You can also use the default one, if you only want to use ACL (authorization):
47
-
```php
48
-
$this->loadComponent('Auth', [
49
-
'authorize' => [
50
-
'TinyAuth.Tiny' => [
51
-
...
52
-
]
53
-
]
54
-
]);
55
-
```
39
+
The TinyAuth.Authorization component extends the official `cakephp/authorization` plugin and adds INI-based access control on top of it.
56
40
57
41
58
42
## Roles
@@ -279,38 +263,38 @@ By default it will not use caching in debug mode, though.
279
263
280
264
To modify the caching behavior set the ``autoClearCache`` configuration option:
281
265
```php
282
-
'TinyAuth.Tiny' => [
283
-
'autoClearCache' => true|false
284
-
]
266
+
$this->loadComponent('TinyAuth.Authorization', [
267
+
'autoClearCache' => true|false,
268
+
]);
285
269
```
286
270
287
271
## Configuration
288
272
289
273
TinyAuthorize adapter supports the following configuration options.
290
274
291
-
Option | Type | Description
292
-
:----- | :--- | :----------
293
-
roleColumn|string|Name of column in user table holding role id (used for foreign key in users table in a single role per user setup, or in the pivot table on multi-roles setup)
294
-
userColumn|string|Name of column in pivot table holding role id (only used in pivot table on multi-roles setup)
295
-
aliasColumn|string|Name of the column for the alias in the role table
296
-
idColumn|string|Name of the ID Column in users table
297
-
rolesTable|string|Name of Configure key holding all available roles OR class name of roles database table
298
-
usersTable|string|Class name of the users table.
299
-
pivotTable|string|Name of the pivot table, for a multi-group setup.
300
-
rolesTablePlugin|string|Name of the plugin for the roles table, if any.
301
-
pivotTablePlugin|string|Name of the plugin for the pivot table, if any.
302
-
multiRole|bool|True will enable multi-role/HABTM authorization (requires a valid join table).
303
-
superAdminRole|int|Id of the super admin role. Users with this role will have access to ALL resources.
304
-
superAdmin|int or string|Id/name of the super admin. Users with this id/name will have access to ALL resources. null/0/'0' disable it.
305
-
superAdminColumn|string|Column of super admin in user table. Default is idColumn option.
306
-
authorizeByPrefix|bool/array|If prefixed routes should be auto-handled by their matching role name or a prefix=>role map.
307
-
allowLoggedIn|bool|True will give authenticated users access to all resources except those using the `protectedPrefix`.
308
-
protectedPrefix|string/array|Name of the prefix(es) used for admin pages. Defaults to `Admin`.
309
-
autoClearCache|bool|True will generate a new ACL cache file every time.
310
-
aclFilePath|string|Full path to the auth_acl.ini. Can also be an array of multiple paths. Defaults to `ROOT . DS . 'config' . DS`.
311
-
aclFile|string|Name of the INI file. Defaults to `auth_acl.ini`.
312
-
aclAdapter|string|Class name, defaults to `IniAclAdapter::class`.
313
-
includeAuthentication|bool|Set to true to include public auth access into hasAccess() checks. Note, that this requires Configure configuration.
roleColumn | string | Name of column in user table holding role id (used for foreign key in users table in a single role per user setup, or in the pivot table on multi-roles setup)
278
+
userColumn | string | Name of column in pivot table holding role id (only used in pivot table on multi-roles setup)
279
+
aliasColumn | string | Name of the column for the alias in the role table
280
+
idColumn | string | Name of the ID Column in users table
281
+
rolesTable | string | Name of Configure key holding all available roles OR class name of roles database table
282
+
usersTable | string | Class name of the users table.
283
+
pivotTable | string | Name of the pivot table, for a multi-group setup.
284
+
rolesTablePlugin | string | Name of the plugin for the roles table, if any.
285
+
pivotTablePlugin | string | Name of the plugin for the pivot table, if any.
286
+
multiRole | bool | True will enable multi-role/HABTM authorization (requires a valid join table).
287
+
superAdminRole | int | Id of the super admin role. Users with this role will have access to ALL resources.
288
+
superAdmin | int or string | Id/name of the super admin. Users with this id/name will have access to ALL resources. null/0/'0' disable it.
289
+
superAdminColumn | string | Column of super admin in user table. Default is idColumn option.
290
+
authorizeByPrefix | bool/array | If prefixed routes should be auto-handled by their matching role name or a prefix=>role map.
291
+
allowLoggedIn | bool | True will give authenticated users access to all resources except those using the `protectedPrefix`.
292
+
protectedPrefix | string/array | Name of the prefix(es) used for admin pages. Defaults to `Admin`.
293
+
autoClearCache | bool | True will generate a new ACL cache file every time.
294
+
aclFilePath | string | Full path to the auth_acl.ini. Can also be an array of multiple paths. Defaults to `ROOT . DS . 'config' . DS`.
295
+
aclFile | string | Name of the INI file. Defaults to `auth_acl.ini`.
296
+
aclAdapter | string | Class name, defaults to `IniAclAdapter::class`.
297
+
includeAuthentication | bool | Set to true to include public auth access into hasAccess() checks. Note, that this requires Configure configuration.
314
298
315
299
## AuthUser Component
316
300
Add the AuthUserComponent and you can easily check permissions inside your controller scope:
Copy file name to clipboardExpand all lines: docs/Multi-role.md
+12-5Lines changed: 12 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,7 @@
1
1
## Configuration Multi-role
2
2
3
+
**IMPORTANT:** First install the official plugins as described in [docs/README.md](README.md#required-dependencies)
4
+
3
5
```php
4
6
// in your app.php
5
7
'TinyAuth' => [
@@ -9,13 +11,18 @@
9
11
10
12
```php
11
13
// in your AppController.php
12
-
$this->loadComponent('TinyAuth.Auth', [
13
-
'autoClearCache' => true,
14
-
'authorize' => ['TinyAuth.Tiny'],
15
-
...
16
-
]);
14
+
public function initialize() {
15
+
parent::initialize();
16
+
17
+
$this->loadComponent('TinyAuth.Authentication');
18
+
$this->loadComponent('TinyAuth.Authorization', [
19
+
'autoClearCache' => true,
20
+
]);
21
+
}
17
22
```
18
23
24
+
See [AuthenticationPlugin.md](AuthenticationPlugin.md) and [AuthorizationPlugin.md](AuthorizationPlugin.md) for complete middleware setup instructions.
0 commit comments