Skip to content

Commit acf8660

Browse files
dereuromarkjosbeir
andauthored
New major (#159)
* Remove legacy code. * Better docs. * Docs. * Fix PHPStan * Really Fix up BaseMigration file :-) * Auto-fix CS - CS master branch * Update CI * Fix CS. --------- Co-authored-by: Jasper Smet <josbeir@users.noreply.github.com>
1 parent fb10197 commit acf8660

35 files changed

+220
-3100
lines changed

README.md

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,47 @@ A CakePHP plugin to handle authentication and user authorization the easy way.
1212

1313
This branch is for **CakePHP 5.1+**. For details see [version map](https://github.com/dereuromark/cakephp-tinyauth/wiki#cakephp-version-map).
1414

15-
## Features
16-
17-
### Authentication
18-
What are public actions, which ones need login?
19-
20-
- Powerful default configs to get you started right away.
21-
- [Quick Setup](https://github.com/dereuromark/cakephp-tinyauth/blob/master/docs/Authentication.md#quick-setups) for 5 minute integration.
22-
23-
### Authorization
24-
Once you are logged in, what actions can you see with your role(s)?
25-
26-
- Single-role: 1 user has 1 role (users and roles table for example)
27-
- Multi-role: 1 user can have 1...n roles (users, roles and a "roles_users" pivot table for example)
28-
- [Quick Setup](https://github.com/dereuromark/cakephp-tinyauth/blob/master/docs/Authorization.md#quick-setups) for 5 minute integration.
29-
30-
### Useful helpers
31-
- AuthUser Component and Helper for stateful and stateless "auth data" access.
32-
- Authentication Component and Helper for `isPublic()` check on current other other actions.
33-
- Auth DebugKit panel for detailed insights into current URL and auth status, identity content and more.
15+
## Why use TinyAuth as a wrapper for Authentication/Authorization plugins?
16+
17+
TinyAuth now acts as a powerful wrapper around CakePHP's official Authentication and Authorization plugins, providing significant advantages:
18+
19+
### 🚀 Zero-Code Configuration
20+
- **INI-based setup**: Define all your authentication and authorization rules in simple INI files
21+
- **No controller modifications**: Unlike vanilla plugins that require code in every controller
22+
- **Plugin-friendly**: Automatically works with third-party plugins without modifications
23+
24+
### ⚡ Lightning Fast Setup
25+
- **5-minute integration**: Get authentication and authorization working in minutes, not hours
26+
- **Sensible defaults**: Pre-configured settings that work for 90% of use cases
27+
- **Quick setups**: Built-in configurations for common scenarios (public non-prefixed, admin areas, etc.)
28+
29+
### 🛠️ Developer Experience
30+
- **Centralized management**: All auth rules in one place, not scattered across controllers
31+
- **Easy maintenance**: Change access rules without touching code
32+
- **Cache optimized**: Built-in caching for maximum performance
33+
- **DebugKit panel**: Visualize auth status, identity, and permissions in real-time
34+
35+
### 🔧 Flexibility
36+
- **Adapter pattern**: Use INI files, database, or custom adapters for rule storage
37+
- **Progressive enhancement**: Start simple, add complexity only when needed
38+
- **Stand-alone components**: Use AuthUser component/helper independently if needed
39+
40+
### 📊 When to Choose TinyAuth
41+
42+
Choose TinyAuth when you want:
43+
- ✅ Simple role-based access control (RBAC)
44+
- ✅ Quick setup without extensive configuration
45+
- ✅ Controller-action level permissions
46+
- ✅ Easy-to-manage access rules
47+
- ✅ Minimal code changes
48+
49+
Since this plugin just further extends the official ones, you can skip the plugin's authentication and authorization components, and use the original plugins' functionality if you want:
50+
- ❌ Complex policy-based authorization
51+
- ❌ Resource-level permissions (per-entity authorization)
52+
- ❌ Middleware/routing level authentication
53+
- ❌ Custom authentication flows
54+
55+
You can still use the other helpers of this plugin, however.
3456

3557
## What's the idea?
3658
Default CakePHP authentication and authorization depends on code changes in at least each controller, maybe more classes.

docs/Authentication.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ At the same time you can always set up "deny" rules for any allowed prefix to re
4242

4343
## Enabling
4444

45-
**DEPRECATED** Use `TinyAuth.Authentication` instead. Rest of the page is accurate.
46-
4745
Authentication is set up in your controller's `initialize()` method:
4846

4947
```php
@@ -52,7 +50,7 @@ Authentication is set up in your controller's `initialize()` method:
5250
public function initialize() {
5351
parent::initialize();
5452

55-
$this->loadComponent('TinyAuth.Auth');
53+
$this->loadComponent('TinyAuth.Authentication');
5654
}
5755
```
5856

@@ -130,14 +128,14 @@ use Cake\Event\EventInterface;
130128
public function beforeFilter(EventInterface $event): void {
131129
parent::beforeFilter($event);
132130

133-
$this->Auth->allow(['index', 'view']);
131+
$this->Authentication->allowUnauthenticated(['index', 'view']);
134132
}
135133
```
136134
This can be interested when migrating slowly to TinyAuth, for example.
137135
Once you move such a code based rule into the INI file, you can safely remove those lines of code in your controller :)
138136

139137
### allow() vs deny()
140-
Since 1.11.0 you can also mix it with `deny()` calls. From how the AuthComponent works, all allow() calls need be done before calling deny().
138+
Since 1.11.0 you can also mix it with `deny()` calls. From how the Authentication component works, all allow() calls need be done before calling deny().
141139
As such TinyAuth injects its list now before `Controller::beforeFilter()` gets called.
142140

143141
Note: It is also advised to move away from these controller calls.
@@ -180,7 +178,7 @@ echo $this->Form->control('password', ['autocomplete' => 'off']);
180178

181179
## Configuration
182180

183-
TinyAuth AuthComponent supports the following configuration options.
181+
TinyAuth Authentication component supports the following configuration options.
184182

185183
Option | Type | Description
186184
:----- | :--- | :----------

docs/README.md

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ You can activate an "Auth" DebugKit panel to have useful insights per URL.
1616
See [AuthPanel](AuthPanel.md) docs.
1717

1818
## Authentication
19-
This is done via TinyAuth AuthComponent.
19+
This is done via TinyAuth Authentication component.
2020

2121
The component plays well together with the authorization part (see below).
2222
If you do not have any roles and either all are logged in or not logged in you can also use this stand-alone to make certain pages public.
@@ -27,7 +27,7 @@ See [Authentication](Authentication.md) docs.
2727
The TinyAuthorize adapter takes care of authorization.
2828

2929
The adapter plays well together with the component above.
30-
But if you prefer to control the action whitelisting for authentication via code and `$this->Auth->allow()` calls, you can
30+
But if you prefer to control the action whitelisting for authentication via code and `$this->Authentication->allowUnauthenticated()` calls, you can
3131
also just use this adapter stand-alone for the ACL part of your application.
3232

3333
There is also an AuthUserComponent and AuthUserHelper to assist you in making role based decisions or displaying role based links in your templates.
@@ -82,14 +82,29 @@ See the docs for details:
8282
- [TinyAuth and Authentication plugin](AuthenticationPlugin.md)
8383
- [TinyAuth and Authorization plugin](AuthorizationPlugin.md)
8484

85-
### When to use the new plugins?
86-
They are super powerful, but they also require a load of config to get them to run.
87-
If you need authentication/authorization on middleware/routing level however, you need
88-
to use them.
85+
### Why use TinyAuth with the new plugins?
86+
87+
TinyAuth provides a powerful abstraction layer over the official Authentication and Authorization plugins:
8988

90-
If you only need the basic request policy provided by this plugin, and no further ORM or other policies,
91-
then it is best to stick to the Auth component as simple wrapper.
92-
It is then limited to controller scope (no middleware/routing support) as it always has been so far.
89+
**Benefits of using TinyAuth:**
90+
- **Zero-code configuration**: All auth rules in INI files, no controller modifications needed
91+
- **Instant setup**: Working authentication/authorization in under 5 minutes
92+
- **Plugin compatibility**: Works automatically with all plugins without modifications
93+
- **Centralized management**: All rules in one place, not scattered across controllers
94+
- **Performance**: Built-in caching for optimal speed
95+
- **Developer friendly**: DebugKit panel, clear error messages, easy debugging
96+
97+
**When to use vanilla plugins' functionality directly:**
98+
They are super powerful, but they also require a load of config to get them to run.
99+
Consider using them (partially) directly when you need:
100+
- Authentication/authorization on middleware/routing level
101+
- Complex policy-based authorization (ORM policies, custom voters)
102+
- Per-entity authorization rules
103+
- Custom authentication flows
104+
105+
**When to use TinyAuth wrapper:**
106+
If you only need the basic request policy provided by this plugin (controller-action level permissions),
107+
then TinyAuth provides a much simpler and faster solution.
93108

94109
You can seamlessly upgrade to the new plugins while keeping your INI files.
95110
They are also compatible with AuthUser component and helper as well as the Auth panel.

phpstan.neon

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,3 @@ parameters:
77
ignoreErrors:
88
- identifier: missingType.iterableValue
99
- identifier: missingType.generics
10-
- '#Constructor of class .+SessionStorage has an unused parameter \$response#'
11-
- '#PHPDoc tag @mixin contains invalid type .+InstanceConfigTrait.#'

src/Auth/AbstractPasswordHasher.php

Lines changed: 0 additions & 79 deletions
This file was deleted.

src/Auth/AclTrait.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ protected function _mapped(array $roles) {
644644
continue;
645645
}
646646

647+
/** @var string $alias */
647648
$array[$alias] = $role;
648649
}
649650

src/Auth/AuthUserTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* define('USER_ROLE_KEY', 'role_id');
3434
* ```
3535
*
36-
* Note: This uses AuthComponent internally to work with both stateful and stateless auth.
36+
* Note: This uses Identity from Authentication plugin.
3737
*
3838
* @author Mark Scherer
3939
* @license MIT

0 commit comments

Comments
 (0)