• Stars
    star
    128
  • Rank 281,044 (Top 6 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 10 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

CakePHP TinyAuth plugin for an easy and fast user authentication and authorization. Single or multi role. DB or config file based.

CakePHP TinyAuth Plugin

CI Latest Stable Version Coverage Status Minimum PHP Version License Total Downloads Coding Standards

A CakePHP plugin to handle authentication and user authorization the easy way.

This branch is for CakePHP 4.2+. For details see version map.

Features

Authentication

What are public actions, which ones need login?

  • Powerful wildcard (*) operator.
  • Quick Setup for 5 minute integration.

Authorization

Once you are logged in, what actions can you see with your role(s)?

  • Single-role: 1 user has 1 role (users and roles table for example)
  • Multi-role: 1 user can have 1...n roles (users, roles and a "roles_users" pivot table for example)
  • Quick Setup for 5 minute integration.

Useful helpers

  • AuthUser Component and Helper for stateful and stateless "auth data" access.
  • Authentication Component and Helper for isPublic() check on current other other actions.
  • Auth DebugKit panel for detailed insights into current URL and auth status.

What's the idea?

Default CakePHP authentication and authorization depends on code changes in at least each controller, maybe more classes. This plugin hooks in with a single line of change and manages all that using config files and there is no need to touch all those controllers, including plugin controllers.

It is also possible to manage the config files without the need to code. And it can with adapters also be moved completely to the DB and managed by CRUD backend.

Ask yourself: Do you need the overhead and complexity involved with the full blown (RBAC DB) ACL? See also my post acl-access-control-lists-revised/. If not, then this plugin could very well be your answer and a super quick solution to your auth problem :)

But even if you don't leverage the authentication or authorization, the available AuthUserComponent and AuthUserHelper can be very useful when dealing with role based decisions in your controller or view level. They also work stand-alone.

Demo

See https://sandbox.dereuromark.de/auth-sandbox

auth_allow.ini

Define the public actions (accessible by anyone) per controller:

Users = index,view
Admin/Maintenance = pingCheck
PluginName.SomeController = *
MyPlugin.Api/V1 = *

auth_acl.ini

Define what actions may be accessed by what logged-in user role:

[Users]
index = *
add,edit = user,super-user

[Admin/Users]
* = admin

[Translate.Admin/Languages]
* = *

AuthUser component and helper

$currentId = $this->AuthUser->id();

$isMe = $this->AuthUser->isMe($userEntity->id);

if ($this->AuthUser->hasRole('mod')) {
}

if ($this->AuthUser->hasAccess(['action' => 'secretArea'])) {
}

// Helper only
echo $this->AuthUser->link('Admin Backend', ['prefix' => 'Admin', 'action' => 'index']);
echo $this->AuthUser->postLink('Delete', ['action' => 'delete', $id], ['confirm' => 'Sure?']);

Installation

Including the plugin is pretty much as with every other CakePHP plugin:

composer require dereuromark/cakephp-tinyauth

Then, to load the plugin either run the following command:

bin/cake plugin load TinyAuth

or manually add the following line to your app's src/Application.php file's bootstrap() function:

$this->addPlugin('TinyAuth');

That's it. It should be up and running.

Docs

For setup and usage see Docs.

Also note the original blog post and how it all started.

More Repositories

1

cakephp-tools

A CakePHP Tools plugin containing lots of useful helpers, behaviors, components, shells, ...
PHP
336
star
2

cakephp-queue

Queue plugin for CakePHP - simple, pure PHP and without dependencies.
PHP
304
star
3

cakephp-ide-helper

IDE Helper plugin for CakePHP
PHP
182
star
4

media-embed

A PHP library to deal with all those media services around, parsing their URLs and displaying their audios/videos.
PHP
175
star
5

cakephp-sandbox

A CakePHP Sandbox app to test and showcase misc. features and tools.
PHP
59
star
6

cakephp-ajax

AJAX for CakePHP: A plugin to ease handling AJAX requests.
PHP
57
star
7

cakephp-geo

A CakePHP plugin around geocoding tools and helpers.
PHP
47
star
8

CakePHP-DatabaseLog

DatabaseLog CakePHP plugin to log into DB instead of files. Better to filter and search.
PHP
43
star
9

cakephp-shim

CakePHP plugin to "shim" functionality up and down for major versions of the framework.
PHP
37
star
10

cakephp-hashid

CakePHP plugin to use hashids for your database table lookups
PHP
36
star
11

cakephp-upgrade

Enhanced Upgrade Plugin for CakePHP2.x (Upgrade from 1.x up to 2.3 or even 3.0)
PHP
36
star
12

cakephp-setup

CakePHP Setup Plugin - containing useful management and debugging tools for CakePHP apps
PHP
34
star
13

cakephp-cache

CakePHP Cache plugin for caching views as static cache files.
PHP
32
star
14

cakephp-dto

CakePHP DTO plugin - quickly generate useful data transfer objects for your app (mutable/immutable)
PHP
24
star
15

executionorder

A demo app to display dispatching and execution order of files and callbacks in a CakePHP app. Try it out!
PHP
21
star
16

composer-prefer-lowest

Checks prefer-lowest installation for actually defined min versions in composer.json
PHP
20
star
17

cakephp-translate

A CakePHP plugin to manage translations of your static content the easy way via web backend.
PHP
17
star
18

cakephp-calendar

CakePHP plugin to render simple calendars or ical/ics files
PHP
16
star
19

CakePHP-Payment-Plugin

Plugin for Payments with Bitcoin, ...
PHP
16
star
20

cakephp-tags

CakePHP Tags Plugin
PHP
14
star
21

cakephp-transifex

A CakePHP plugin to manage locales/translations via Transifex API
PHP
14
star
22

cakephp-whoops

Whoops Error Handler for CakePHP - PHP errors and exceptions for cool kids
PHP
13
star
23

cakephp-feed

CakePHP Plugin with RssView to create RSS feeds.
PHP
13
star
24

cakephp-data

CakePHP Data plugin
PHP
12
star
25

cakephp-flash

A CakePHP Flash plugin for more powerful flash messages
PHP
12
star
26

cakefest

A fun/test project around the annual CakePHP CakeFest Conference.
HTML
10
star
27

cakephp-captcha

Dead simple, unobtrusive and extendable captcha solution for CakePHP
PHP
10
star
28

cakephp-ratings

Ratings Plugin for CakePHP
PHP
9
star
29

cakephp-expose

CakePHP Expose plugin to expose entities through additional UUIDs instead of their AIID primary keys
PHP
8
star
30

cakephp-decimal

CakePHP Decimal type handling using Decimal value object.
PHP
8
star
31

cakephp-test-helper

Helper plugin around CakePHP testing and TDD as browser backend
PHP
7
star
32

cakephp-meta

CakePHP Meta plugin for managing meta tags and SEO related HTML header markup.
PHP
7
star
33

cakephp-feedback

A CakePHP plugin for direct feedback or bugreport (with screenshot!) tab option in your app.
PHP
6
star
34

cakephp-queue-scheduler

CakePHP Addon for Queue plugin to schedule commands and queue tasks as crontab like DB solution
PHP
6
star
35

cakephp-qrcode

QR Code Plugin for CakePHP
PHP
6
star
36

cakephp-file-storage

Abstract file storage and upload plugin for CakePHP. Write to local disk, FTP, S3, Dropbox and more through a single interface. It's not just yet another uploader but a complete storage solution.
PHP
4
star
37

cakephp-math

Math Plugin for CakePHP
PHP
3
star
38

cakephp-markup

CakePHP plugin for markup (parsing and displaying)
PHP
3
star
39

cakephp-tinyauth-backend

A database driven backend for CakePHP TinyAuth plugin
PHP
2
star
40

auth-demo

CakePHP Demo Application for Authentication and Authorization plugins, based on TinyAuth wrapper
PHP
2
star
41

cakephp-menu

Powerful Menu plugin for CakePHP
PHP
2
star
42

cakephp-ide-helper-extra

IdeHelper task and addon collection
SCSS
2
star
43

cakephp-templating

A plugin for templating in CakePHP with HTML value objects, font-icons and useful helpers
PHP
2
star
44

cakephp-trailing-slash

Legacy support for Cake apps that still use/need trailing slash routing
PHP
1
star
45

cakephp-navigation

Navigation plugin for CakePHP, including sitemap, menu and breadcrumb generation
PHP
1
star
46

PHP

PHP draft for argument order fix
PHP
1
star
47

cakephp-opensearch

CakePHP Open Search plugin/helper for creating installable search plugins for IE, Firefox and Chrome
PHP
1
star
48

cakephp-favorites

Favorites Plugin for CakePHP
PHP
1
star
49

cakephp-comments

Comments Plugin for CakePHP
PHP
1
star
50

sandbox-docker

Docker container setup for the CakePHP sandbox
Dockerfile
1
star