Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/tmp/
/composer.lock
/composer.phar
/.idea
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ language: php
sudo: false

php:
- 5.4
- 5.5
- 5.6
- 7.0
Expand Down
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,37 @@
[![Build Status](https://api.travis-ci.org/dereuromark/cakephp-tinyauth.svg?branch=master)](https://travis-ci.org/dereuromark/cakephp-tinyauth)
[![Latest Stable Version](https://poser.pugx.org/dereuromark/cakephp-tinyauth/v/stable.svg)](https://packagist.org/packages/dereuromark/cakephp-tinyauth)
[![Coverage Status](https://coveralls.io/repos/dereuromark/cakephp-tinyauth/badge.svg)](https://coveralls.io/r/dereuromark/cakephp-tinyauth)
[![Minimum PHP Version](http://img.shields.io/badge/php-%3E%3D%205.4-8892BF.svg)](https://php.net/)
[![Minimum PHP Version](http://img.shields.io/badge/php-%3E%3D%205.5-8892BF.svg)](https://php.net/)
[![License](https://poser.pugx.org/dereuromark/cakephp-tinyauth/license.svg)](https://packagist.org/packages/dereuromark/cakephp-tinyauth)
[![Total Downloads](https://poser.pugx.org/dereuromark/cakephp-tinyauth/d/total.svg)](https://packagist.org/packages/dereuromark/cakephp-tinyauth)
[![Coding Standards](https://img.shields.io/badge/cs-PSR--2--R-yellow.svg)](https://github.com/php-fig-rectified/fig-rectified-standards)

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

## Demo
See http://sandbox3.dereuromark.de/auth-sandbox

### auth-allow.ini
```ini
Users = index,view
PluginName.SomeController = *
```

### acl.ini
```ini
[Users]
index = *
add,edit = user, mod
* = admin
add,edit = user,mod

[admin/Users]
* = admin
```

See http://sandbox3.dereuromark.de/auth-sandbox

## How to include
Installing the plugin is pretty much as with every other CakePHP Plugin.
Installing the plugin is pretty much as with every other CakePHP plugin:

```bash
composer require dereuromark/cakephp-tinyauth:dev-master
composer require dereuromark/cakephp-tinyauth
```

Then, to load the plugin either run the following command:
Expand All @@ -45,7 +51,7 @@ Plugin::load('TinyAuth');
That's it. It should be up and running.

## Docs
See [Docs](/docs).
For setup and usage see [Docs](/docs).

Also note the original [blog post](http://www.dereuromark.de/2011/12/18/tinyauth-the-fastest-and-easiest-authorization-for-cake2/) and how it all started.

Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
}
],
"require": {
"php": ">=5.4",
"cakephp/cakephp": "~3.0"
"php": ">=5.5",
"cakephp/cakephp": "~3.2"
},
"require-dev": {
"fig-r/psr2r-sniffer": "dev-master"
Expand All @@ -30,7 +30,8 @@
"autoload-dev": {
"psr-4": {
"TinyAuth\\Test\\": "tests",
"Cake\\Test\\": "vendor/cakephp/cakephp/tests"
"Cake\\Test\\": "vendor/cakephp/cakephp/tests",
"TestApp\\": "tests/TestApp"
}
},
"extra": {
Expand Down
5 changes: 5 additions & 0 deletions config/auth-allow.default.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Users = index, view ; Everyone can access index and view actions
admin/Users = index ; Only index action is public for admin prefix
Extras.Offers = * ; All Offers controller actions in Extras plugin are public

; ...
93 changes: 93 additions & 0 deletions docs/Authentication.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# TinyAuth Authentication
The fast and easy way for user authentication in CakePHP 3.x applications.

Use TinyAuth Componont if you want to add instant (and easy) action whitelisting to your application.

## Basic Features
- INI file (static) based access rights (controller-action setup)
- Lightweight and incredibly fast

Do NOT use if
- you want to dynamically adjust access rights (or enhance it with a web
frontend yourself)

## Enabling

Authentication is set up in your controller's `initialize` method:

```php
// src/Controller/AppController

public function initialize() {
$this->loadComponent('TinyAuth.Auth', [
'filePath' => ...
]);
}
```

## auth-allow.ini

TinyAuth expects an ``auth-allow.ini`` file in your config directory.
Use it to specify what actions are not protected by authentication.

The section key syntax follows the CakePHP naming convention for plugins.

Make sure to create an entry for each action you want to expose and use:

- one or more action names
- the ``*`` wildcard to allow access to all actions of that controller

```ini
; ----------------------------------------------------------
; UsersController
; ----------------------------------------------------------
Users = index
; ----------------------------------------------------------
; UsersController using /api prefixed route
; ----------------------------------------------------------
api/Users = index, view, edit
; ----------------------------------------------------------
; UsersController using /admin prefixed route
; ----------------------------------------------------------
admin/Users = *
; ----------------------------------------------------------
; AccountsController in plugin named Accounts
; ----------------------------------------------------------
Accounts.Accounts = view, edit
; ----------------------------------------------------------
; AccountsController in plugin named Accounts using /admin
; prefixed route
; ----------------------------------------------------------
Accounts.admin/Accounts = index
```

## Caching

TinyAuth makes heavy use of caching to achieve optimal performance.

You may however want to disable caching while developing to prevent
confusing (outdated) results.

To disable caching either:

- pass ``true`` to the ``autoClearCache`` configuration option
- use the example below to disable caching automatically for CakePHP debug mode

```php
$this->loadComponent('TinyAuth.Auth', [
'autoClearCache' => Configure::read('debug')
)]
```

## Configuration

TinyAuth AuthComponent supports the following configuration options.

Option | Type | Description
:----- | :--- | :----------
autoClearCache|bool|True will generate a new ACL cache file every time.
filePath|string|Full path to the acl.ini. Defaults to `ROOT . DS . 'config' . DS`.
file|string|Name of the INI file. Defaults to `auth-allow.ini`.
cache|string|Cache type. Defaults to `_cake_core_`.
cacheKey|string|Cache key. Defaults to `tiny_auth_allow`.

Loading