Skip to content

Commit 9770400

Browse files
committed
Merge pull request #13 from bravo-kernel/database-docs
Logical split of roles and user usage instructions
2 parents d088cb9 + 5ae2d29 commit 9770400

File tree

1 file changed

+82
-10
lines changed

1 file changed

+82
-10
lines changed

docs/README.md

Lines changed: 82 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
# TinyAuth Authorization
22
The fast and easy way for user authorization in CakePHP 3.x applications.
33

4-
Enable TinyAuth Authorize adapter if you want to add instant (and easy) role based
5-
access (RBAC) to your application.
4+
Enable TinyAuth Authorize adapter if you want to add instant (and easy) role
5+
based access (RBAC) to your application.
66

77
## Basic Features
8-
- Singe or multi role
8+
- Single or multi role
99
- DB (dynamic) or Configure based role definition
1010
- INI file (static) based access rights (controller-action/role setup)
1111
- Lightweight and incredibly fast
1212

1313
Do NOT use if
1414
- you need ROW based access
15-
- you want to dynamically adjust access rights (or enhance it with a web frontend yourself)
15+
- you want to dynamically adjust access rights (or enhance it with a web
16+
frontend yourself)
1617

1718
## Enabling
1819

@@ -30,19 +31,30 @@ public function beforeFilter(Event $event) {
3031
$this->loadComponent('Auth', [
3132
'authorize' => [
3233
'TinyAuth.Tiny' => [
34+
'multiRole' => false,
3335
'allowUser' => false,
3436
'authorizeByPrefix' => false,
3537
'prefixes' => [],
36-
'superAdminRole' => null
38+
'superAdminRole' => null,
39+
'autoClearCache' => false
3740
]
3841
]
3942
]);
4043
}
4144
```
4245

46+
> Please note that TinyAuth Authorize can be used in combination with any
47+
> [CakePHP Authentication Type](http://book.cakephp.org/3.0/en/controllers/components/authentication.html#choosing-an-authentication-type).
48+
4349
## Roles
4450

45-
You need to define some roles for TinyAuth to work, for example:
51+
TinyAuth requires the presence of roles to function so create those first using
52+
one of the following two options.
53+
54+
### Configure based roles
55+
56+
Define your roles in a Configure array if you want to prevent database role
57+
lookups, for example:
4658

4759
```php
4860
// config/app_custom.php
@@ -63,10 +75,52 @@ return [
6375
];
6476
```
6577

66-
You do not have to configure the Roles array if you use DB driven roles.
67-
You can however avoid the DB lookups this way if you want to.
68-
For the DB driven approach make sure you have an "alias" field in your roles table
69-
as slug identifier for the acl.ini file.
78+
### Database roles
79+
When you choose to store your roles in the database TinyAuth expects a table
80+
named ``roles``. If you prefer to use another table name simply specify it using the
81+
``rolesTable`` configuration option.
82+
83+
>**Note:** make sure to add an "alias" field to your roles table (used as slug
84+
identifier in the acl.ini file)
85+
86+
Example of a record from a valid roles table:
87+
88+
```php
89+
'id' => '11'
90+
'name' => 'User'
91+
'description' => 'Basic authenticated user'
92+
'alias' => 'user'
93+
'created' => '2010-01-07 03:36:33'
94+
'modified' => '2010-01-07 03:36:33'
95+
```
96+
97+
> Please note that you do NOT need Configure based roles when using database
98+
> roles. Also make sure to remove (or rename) existing Configure based roles
99+
> since TinyAuth will always first try to find a matching Configure roles array
100+
> before falling back to using the database.
101+
102+
## Users
103+
104+
### Single-role
105+
106+
When using the single-role-per-user model TinyAuth expects your Users model to
107+
contain an column named ``role_id``. If you prefer to use another column name
108+
simply specify it using the ``roleColumn`` configuration option.
109+
110+
### Multi-role
111+
When using the multiple-roles-per-user model:
112+
113+
- your database MUST have a ``roles`` table
114+
- your database MUST have a valid join table (e.g. ``roles_users``)
115+
- the configuration option ``multiRole`` MUST be set to ``true``
116+
117+
Example of a record from a valid join table:
118+
119+
```php
120+
'id' => 1
121+
'user_id' => 1
122+
'role_id' => 1
123+
```
70124

71125
## acl.ini
72126

@@ -125,6 +179,24 @@ view, edit = user
125179
* = admin
126180
```
127181

182+
## Caching
183+
184+
TinyAuth makes heavy use of caching to achieve optimal performance.
185+
186+
You may however want to disable caching while developing RBAC to prevent
187+
confusing (outdated) results.
188+
189+
To disable caching either:
190+
191+
- pass ``true`` to the ``autoClearCache`` configuration option
192+
- use the example below to disable caching automatically for CakePHP debug mode
193+
194+
```php
195+
'TinyAuth.Tiny' => [
196+
'autoClearCache' => Configure::read('debug')
197+
]
198+
```
199+
128200
## Configuration
129201

130202
TinyAuth supports the following configuration options.

0 commit comments

Comments
 (0)