Getting started
Configure TinyAuth for an application that already has working login, an identity with role information, and the official Authentication and Authorization middleware. Complete Installation first. The Authentication and Authorization guides cover those prerequisites.
1. Whitelist public actions
Create config/auth_allow.ini:
Pages = display
Users = login, register, forgotPassword
; everything not listed here will require authenticationAuthentication rules use Controller = action, otherAction, without INI sections. * allows every action of that controller to be public. Roles apply to the separate ACL file below.
2. Map your roles
Define the role aliases in config/app.php, using the values stored in your users' role_id field:
'Roles' => [
'user' => 1,
'admin' => 2,
],These IDs are examples. Match them to your existing users and configure roleColumn if you use another field.
3. Define role permissions
Create config/auth_acl.ini (only needed if you also use authorization):
[Pages]
* = *
[Users]
* = admin
profile = user, admin
edit = user, admin
[Admin/Users]
* = adminEach section is a controller (or Prefix/Controller). Each line maps actions = roles.
4. Load TinyAuth components
In AppController:
public function initialize(): void {
parent::initialize();
$this->loadComponent('TinyAuth.Authentication');
$this->loadComponent('TinyAuth.Authorization');
}With the underlying services and login redirects configured, non-public actions require authentication. Logged-in users are checked against auth_acl.ini. Adapt the controller and action names to the routes in your application.
TinyAuth does not create these controllers or actions. The edit rule grants request access; use an entity policy to check whether a user may edit a particular record.
5. Verify in the browser
- Open a URL routed to
Pages::display, such as/in the default CakePHP application: it works without login. - Open your
Users::indexroute without login: it redirects to your configured login URL. - Log in and open your
Users::profileroute with theuserrole: access is allowed. A role absent from that rule is forbidden.
Where to next
- Authentication: full options for the Authentication component, INI syntax for
auth_allow.ini. - Authorization: full options for the Authorization component, INI syntax for
auth_acl.ini. - Multi-role setup: when a user has more than one role.
- AuthUser: controller / view helpers for "is this user an admin?" checks.
- AuthPanel: DebugKit panel for inspecting decisions.
- Troubleshooting: when something doesn't behave.