2017 © Pedro Peláez
 

cakephp-plugin authenticate

CakePHP plugin with authentication classes for AuthComponent.

image

friendsofcake/authenticate

CakePHP plugin with authentication classes for AuthComponent.

  • Tuesday, December 22, 2015
  • by FriendsOfCake
  • Repository
  • 17 Watchers
  • 82 Stars
  • 24,900 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 39 Forks
  • 1 Open issues
  • 9 Versions
  • 3 % Grown

The README.md

Authenticate plugin

Build Status Coverage Status, (*1)

NOTE: This project is no longer maintained actively.

The Authenticate classes have become redundant or better alternatives have surfaced: * MultiColumnAuthenticate, see Tools - or use custom finders in CakePHP 3 * CookieAuthenticate, see Xety/Cake3-CookieAuth * TokenAuthenticate, see JwtAuth, (*2)

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

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, (*4)

Requirements

  • CakePHP 3.0

Installation

[Composer], (*5)

run: composer require friendsofcake/authenticate:dev-cake3 or add "friendsofcake/authenticate":"dev-cake3" to require section in your application's composer.json., (*6)

Usage

In your app's config/bootstrap.php add: Plugin::load('FOC/Authenticate');, (*7)

Configuration:

Setup the authentication class settings, (*8)

MultiColumnAuthenticate:

    //in $components
    public $components = [
        'Auth' => [
            'authenticate' => [
                'FOC/Authenticate.MultiColumn' => [
                    'fields' => [
                        'username' => 'login',
                        'password' => 'password'
                    ],
                    'columns' => ['username', 'email'],
                    'userModel' => 'Users',
                    'scope' => ['Users.active' => 1]
                ]
            ]
        ]
    ];

    // Or in beforeFilter()
    $this->Auth->config('authenticate', [
        'FOC/Authenticate.MultiColumn' => [
            'fields' => [
                'username' => 'login',
                'password' => 'password'
            ],
            'columns' => ['username', 'email'],
            'userModel' => 'Users',
            'scope' => ['Users.active' => 1]
        ]
    ]);

CookieAuthenticate:

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

Setup both:

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

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

Example for setting the cookie:, (*10)

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

    public $components = ['Cookie'];

    public function login() {
        if ($this->request->is('post')) {
            $user = $this->Auth->identify();
            if ($user) {
                $this->Auth->setUser($user);
                $this->_setCookie();
                return $this->redirect($this->Auth->redirectUrl());
            }
            $this->Flash->error(__('Invalid username or password, try again'));
        }
    }

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

}

TokenAuthenticate

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

The Versions

22/12 2015

dev-master

9999999-dev 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

22/12 2015

dev-ceeram-patch-1

dev-ceeram-patch-1 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

22/12 2015

2.0.0

2.0.0.0 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

17/06 2015

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

08/04 2015

1.0.2

1.0.2.0 http://github.com/FriendsOfCake/Authenticate

CakePHP plugin with authentication classes for AuthComponent.

  Sources   Download

MIT

The Requires

 

by Avatar Ceeram

cakephp authenticate

13/01 2015

1.0.1

1.0.1.0 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