Giter Club home page Giter Club logo

cake3-cookieauth's Introduction

Hi there ๐Ÿ‘‹

  • 34 years and learning the development since 10+ years in autodidact.

  • ๐ŸŒฑ Mainly backend developer with PHP and Laravel, Symfony & CakePHP.

  • ๐Ÿ‘ฏ I have also worked/work with JavaScript, TypeScript, SASS, VueJS, WebPack, Redis...

  • โšกMy personnal website : https://github.com/XetaIO/Xetaravel

Xeta Logo

https://xetaravel.com is a resource to help people starting with Laravel. I have developed this site to try Laravel, and I have decided to release it to help people starting with Laravel, so there is probably some custom configurations/functions that only fit my needs. Now i use this site for my personnal blog.

๐Ÿ† Profile's Stats

Xety's GitHub stats Xety Trophies

cake3-cookieauth's People

Contributors

antograssiot avatar icaroscherma avatar xety avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cake3-cookieauth's Issues

Allow NULL password

I user LDAP for authentication, so I don't store passwords in my users table.

// after authentication by LDAP
$this->Cookie->write('CookieAuth', [
    'username' => $this->request->data('username'),
    'password' => null 
]);

I still want users to be identified by the username, so I had to comment a line out

if (empty($cookies[$username]) /*|| empty($cookies[$password])*/) {
    return false;
}

// the user can be found by his username. The password field is not mandatory
// in BaseAuthenticate.php
$user = $this->_findUser($cookies[$username], $cookies[$password]);
if ($user) {
    return $user;
}

Is this reasonable?

Fatal error: Uncaught Error: Call to a member function read() on boolean for cookies

This is how I have setup my AppController.php, but it is giving error

<?php
namespace App\Controller;

use Cake\Controller\Controller;
use Cake\Event\Event;
use Cake\Core\Configure;

class AppController extends Controller
{
    public function initialize()
    {
        parent::initialize();

        $this->loadComponent('RequestHandler');
        $this->loadComponent('Flash');
        $this->loadComponent('Auth', [
            'loginRedirect' => [
                'controller' => 'Dashboard',
                'action' => 'index'
            ],
            'logoutRedirect' => [
                'controller' => 'Pages',
                'action' => 'home'
            ],
            'authenticate' => [
                'Form' => [
                    'finder' => 'auth',
                ],
                'Xety/Cake3CookieAuth.Cookie' => [
                    'cookie' => [
                        'name' => 'CookieAuth'
                    ]
                ]
            ]
        ]);

        //$this->loadComponent('Security');
        //$this->loadComponent('Csrf');
    }

    public function beforeRender(Event $event)
    {
        $this->loadComponent('Auth');

        // login using cookies
        if (!$this->Auth->user('id') && $this->Cookie->read('CookieAuth')) {
            $user = $this->Auth->identify();
            if ($user) {
                $this->Auth->setUser($user);
            } else {
                $this->Cookie->delete('CookieAuth');
            }
        }

        // set logged in user data to render in view files
        if ($this->Auth->user('id')) {
            $this->set('AUTH_USER', $this->Auth->user());
        }

        if (!array_key_exists('_serialize', $this->viewVars) &&
            in_array($this->response->type(), ['application/json', 'application/xml'])
        ) {
            $this->set('_serialize', true);
        }
    }
}

Error getting is

Fatal error: Uncaught Error: Call to a member function read() on boolean in /var/www/html/emeet.com/emeet_cake/src/Controller/AppController.php:46

on removing $this->Cookie->read('CookieAuth'), error jumped to next Cookie->delete line

Specify authentication fields in the documentation

I have an application using email and password for authentication, and I've had a few problems trying to integrate Cake3-CookieAuth. After some investigation, I have found out that you need to tell CookieAuth which fields are in use:

$this->loadComponent('Auth', [
    'authenticate' => [
        'Form' => [
            'fields' => ['username' => 'email']
        ],
        'Xety/Cake3CookieAuth.Cookie' => [
            'fields' => ['username' => 'email'] // this is what I was missing
        ]
    ],
    ...
]);

I think that this should be explained in the README...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.