PHPackages                             falco442/cakephp-3-token-auth - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. falco442/cakephp-3-token-auth

AbandonedCakephp-plugin

falco442/cakephp-3-token-auth
=============================

TokenAuth plugin for CakePHP

04PHP

Since Oct 17Pushed 9y ago1 watchersCompare

[ Source](https://github.com/falco442/cakephp-3-token-auth-plugin)[ Packagist](https://packagist.org/packages/falco442/cakephp-3-token-auth)[ RSS](/packages/falco442-cakephp-3-token-auth/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Cakephp-TokenAuth Plugin
========================

[](#cakephp-tokenauth-plugin)

This is the plugin for make an authentication done with Tokens.

Requirements
------------

[](#requirements)

- CakePHP 3.x

Installation
============

[](#installation)

Getting plugin
--------------

[](#getting-plugin)

You can install the plugin by manually download, or by composer

```
composer require falco442/cakephp-3-token-auth

```

Preparing tables
----------------

[](#preparing--tables)

Put into the table you use for authentication model ('users') the fields 'token' (varchar(255)) and 'token\_created' (datetime).

Loading plugin
--------------

[](#loading-plugin)

Load the plugin by calling

```
Plugin::loadAll();
```

or

```
Plugin::load('TokenAuth');
```

and put the Authentication object in your `AppController.php`:

```
public function initialize(){

	parent::initialize();

	// ...

    $this->loadComponent('Auth',[
        'authenticate'=>[
            'TokenAuth.Token'
        ],
        'unauthorizedRedirect'=>false,
        'storage'=>'Memory'
    ]);

    // ...
}
```

Keep in mind that you can customize the Authentication object with the same parameters you would have used with FormAuthenticate, like `userModel` and `fields`

Use
===

[](#use)

In Controller
-------------

[](#in-controller)

You can set up the login action for your controller; for example, the action `login()` in `UsersController.php`:

```
public function login(){
	$user = $this->Auth->identify($this->request,$this->response);
	$this->set(compact('user'));
	$this->set('_serialize',['user']);
}
```

Since the token authentication is done mainly for API applications, all you need is to retrieve the `$user` object that contains the new token that TokenAuth automatically generates. This token will be used to do all the calls to the actions that you don't want to be publicly accessible.

If you want an action to be public, simply use

```
$this->Auth->allow(['action-name']);
```

in the `initialize()` method in respective controller.

The non-public routes that a client will call shall be of the form

```
GET /uri.json?token=token-received

```

Reset token
-----------

[](#reset-token)

You can reset token by calling the shell

```
cd cake-root ./bin/cake TokenAuth.token refresh

```

**Note**:

- the reset token task will take '-15 days' as base token life, but you can customize the shell
- the shell take the model `User` as base, but you can set any model you like

Type in console

```
cd cake-root ./bin/cake TokenAuth.token refresh --help

```

to get some help

Useful info
===========

[](#useful-info)

Since we use (mainly) token authentication for api web applications, it is useful to set REST in CakePHP (see [this page](http://book.cakephp.org/2.0/en/development/rest.html)).

This is done with simple steps:

- modify the `cake-root/app/Config/routes.php` by adding `Router::parseExtensions('json','xml');` (or with the extensions you desires)
- in `cake-root/app/Controller/AppController.php` add the `RequestHandler` component; it will parse the extension of the format (json, xml, ...)
- **if you want REST** you can map the resources (as [this page](http://book.cakephp.org/2.0/en/development/rest.html#the-simple-setup) says) with the method `Router::mapResources()`, to be put in `cake-root/app/Config/routes.php`

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/3620abbff28b3934d7ab220236a87b0e9317bdf2a94bbbed68b8ea633a7a417b?d=identicon)[falco442](/maintainers/falco442)

---

Top Contributors

[![falco442](https://avatars.githubusercontent.com/u/11598209?v=4)](https://github.com/falco442 "falco442 (18 commits)")

### Embed Badge

![Health badge](/badges/falco442-cakephp-3-token-auth/health.svg)

```
[![Health](https://phpackages.com/badges/falco442-cakephp-3-token-auth/health.svg)](https://phpackages.com/packages/falco442-cakephp-3-token-auth)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
