2017 © Pedro Peláez
 

cakephp-plugin authenticate

CakePHP plugin with authentication classes for AuthComponent.

image

ceeram/authenticate

CakePHP plugin with authentication classes for AuthComponent.

  • Friday, October 3, 2014
  • by Ceeram
  • Repository
  • 2 Watchers
  • 5 Stars
  • 138 Installations
  • 0 Dependents
  • 0 Suggesters
  • 43 Forks
  • 0 Open issues
  • 9 Versions
  • 1 % Grown

The README.md

Authenticate plugin

Build Status Coverage Status, (*1)

Plugin containing some authenticate classes for AuthComponent., (*2)

Current classes: * MultiColumnAuthenticate, allow login with multiple db columns in single username field For example username or email * CookieAuthenticate, login with a cookie * TokenAuthenticate, login with a token as url parameter or header, (*3)

GoogleAuthenticate is moved to separate repo: https://github.com/ceeram/GoogleAuthenticate, (*4)

Requirements

  • PHP 5.3
  • CakePHP 2.x

Installation

[Composer], (*5)

run: composer require friendsofcake/authenticate or add friendsofcake/authenticate to require in your applications composer.json, (*6)

[Manual], (*7)

  • Download this: http://github.com/FriendsOfCake/Authenticate/zipball/master
  • Unzip that download.
  • Copy the resulting folder to app/Plugin
  • Rename the folder you just copied to Authenticate

[GIT Submodule], (*8)

In your app directory type:, (*9)

git submodule add git://github.com/FriendsOfCake/Authenticate.git Plugin/Authenticate
git submodule init
git submodule update

[GIT Clone], (*10)

In your plugin directory type git clone git://github.com/FriendsOfCake/Authenticate.git Authenticate, (*11)

Usage

In app/Config/bootstrap.php add: CakePlugin::load('Authenticate');, (*12)

Configuration:

Setup the authentication class settings, (*13)

MultiColumnAuthenticate:

    //in $components
    public $components = array(
        'Auth' => array(
            'authenticate' => array(
                'Authenticate.MultiColumn' => array(
                    'fields' => array(
                        'username' => 'login',
                        'password' => 'password'
                    ),
                    'columns' => array('username', 'email'),
                    'userModel' => 'User',
                    'scope' => array('User.active' => 1)
                )
            )
        )
    );
    //Or in beforeFilter()
    $this->Auth->authenticate = array(
        'Authenticate.MultiColumn' => array(
            'fields' => array(
                'username' => 'login',
                'password' => 'password'
            ),
            'columns' => array('username', 'email'),
            'userModel' => 'User',
            'scope' => array('User.active' => 1)
        )
    );

CookieAuthenticate:

    //in $components
    public $components = array(
        'Auth' => array(
            'authenticate' => array(
                'Authenticate.Cookie' => array(
                    'fields' => array(
                        'username' => 'login',
                        'password' => 'password'
                    ),
                    'userModel' => 'SomePlugin.User',
                    'scope' => array('User.active' => 1)
                )
            )
        )
    );
    //Or in beforeFilter()
    $this->Auth->authenticate = array(
        'Authenticate.Cookie' => array(
            'fields' => array(
                'username' => 'login',
                'password' => 'password'
            ),
            'userModel' => 'SomePlugin.User',
            'scope' => array('User.active' => 1)
        )
    );

Setup both:

It will first try to read the cookie, if that fails will try with form data:, (*14)

    //in $components
    public $components = array(
        'Auth' => array(
            'authenticate' => array(
                'Authenticate.Cookie' => array(
                    'fields' => array(
                        'username' => 'login',
                        'password' => 'password'
                    ),
                    'userModel' => 'SomePlugin.User',
                    'scope' => array('User.active' => 1)
                ),
                'Authenticate.MultiColumn' => array(
                    'fields' => array(
                        'username' => 'login',
                        'password' => 'password'
                    ),
                    'columns' => array('username', 'email'),
                    'userModel' => 'User',
                    'scope' => array('User.active' => 1)
                )
            )
        )
    );

Security

For enhanced security, make sure you add this code to your AppController::beforeFilter() if you intend to use Cookie authentication:, (*15)

public function beforeFilter() {
  $this->Cookie->type('rijndael'); //Enable AES symetric encryption of cookie
}

Example for setting the cookie:, (*16)

<?php
App::uses('AppController', 'Controller');
/**
 * Users Controller
 *
 * @property User $User
 */
class UsersController extends AppController {

    public $components = array('Cookie');

    public function beforeFilter() {
        $this->Cookie->type('rijndael');
    }

    public function login() {
        if ($this->Auth->loggedIn() || $this->Auth->login()) {
            $this->_setCookie();
            $this->redirect($this->Auth->redirect());
        }
    }

    protected function _setCookie() {
        if (!$this->request->data('User.remember_me')) {
            return false;
        }
        $data = array(
            'username' => $this->request->data('User.username'),
            'password' => $this->request->data('User.password')
        );
        $this->Cookie->write('User', $data, true, '+1 week');
        return true;
    }

    public function logout() {
        $this->Auth->logout();
        $this->Session->setFlash('Logged out');
        $this->redirect($this->Auth->redirect('/'));
    }
}

TokenAuthenticate

    //in $components
    public $components = array(
        'Auth' => array(
            'authenticate' => array(
                'Authenticate.Token' => array(
                    'parameter' => '_token',
                    'header' => 'X-MyApiTokenHeader',
                    'userModel' => 'User',
                    'scope' => array('User.active' => 1),
                    'fields' => array(
                        'username' => 'username',
                        'password' => 'password',
                        'token' => 'public_key',
                    ),
                    'continue' => true
                )
            )
        )
    );
    //Or in beforeFilter()
    $this->Auth->authenticate = array(
        'Authenticate.Token' => array(
            'parameter' => '_token',
            'header' => 'X-MyApiTokenHeader',
            'userModel' => 'User',
            'scope' => array('User.active' => 1),
            'fields' => array(
                'username' => 'username',
                'password' => 'password',
                'token' => 'public_key',
            ),
            'continue' => true
        )
    );

The Versions

03/10 2014

dev-cake3-tests

dev-cake3-tests http://github.com/FriendsOfCake/Authenticate

CakePHP plugin with authentication classes for AuthComponent.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Ceeram

cakephp authenticate

10/09 2014

dev-3.0-require

dev-3.0-require http://github.com/FriendsOfCake/Authenticate

CakePHP plugin with authentication classes for AuthComponent.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Ceeram

cakephp authenticate

30/08 2014

dev-cake3

dev-cake3 http://github.com/FriendsOfCake/Authenticate

CakePHP plugin with authentication classes for AuthComponent.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Ceeram

cakephp authenticate

11/08 2014

dev-cake3-strict

dev-cake3-strict http://github.com/FriendsOfCake/Authenticate

CakePHP plugin with authentication classes for AuthComponent.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Ceeram

cakephp authenticate

11/08 2014

dev-cake3-travis

dev-cake3-travis http://github.com/FriendsOfCake/Authenticate

CakePHP plugin with authentication classes for AuthComponent.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Ceeram

cakephp authenticate

11/08 2014

dev-master

9999999-dev http://github.com/FriendsOfCake/Authenticate

CakePHP plugin with authentication classes for AuthComponent.

  Sources   Download

MIT

The Requires

 

by Avatar Ceeram

cakephp authenticate

01/04 2014

dev-travisfix

dev-travisfix http://github.com/FriendsOfCake/Authenticate

CakePHP plugin with authentication classes for AuthComponent.

  Sources   Download

MIT

The Requires

 

by Avatar Ceeram

cakephp authenticate

12/09 2013

1.0.0

1.0.0.0 http://github.com/ceeram/Authenticate

CakePHP plugin with authentication classes for AuthComponent.

  Sources   Download

MIT

The Requires

 

13/09 2012

dev-defensie

dev-defensie http://github.com/ceeram/Authenticate

CakePHP plugin with authentication classes for AuthComponent.

  Sources   Download

MIT

The Requires