CakePHP 2 Basic Authentication Authentication

I am moving from CakePHP 1.3 to CakePHP 2.2.2 and want to use Basic Http authentication for a simple administration area. I just can't get it to work, and I think I understood something was wrong in the documentation.

From the documentation, I realized that I need to do something like

public $components = array(
    'Auth' => array(
      'authenticate' => array(
        'Basic'
      ),
      'authError' => 'You may not access this area.',
      'authorize' => array('Controller')
    )
  );

I understand that in the future I need to expand the BaseAuthenticate component to return the actual date of the user, but even with the above configuration, I expect the Http Access Browser dialog to open in a popup window. But nothing of the kind happens, instead I am redirected to / users / login, which is not there. Why do I need a login view for Http Access? I'm confused.

+5
1

Auth ( AppController)

class ThingsController extends AppController {  
    var $components = array('Auth');
}

CakePHP , , , HTTP , - , ( WWW-Authenticate: Basic, ).

AuthCompoment $loginAction, ( ) login UsersController. , View/Users/login.ctp, UsersController

class UsersController extends AppController {

    public $components = array(
        'Session',
        'Auth' => array(
            'authenticate' => array('Basic')
        )
    );

    public function login() {
        if ($this->Auth->login()) {
            return $this->redirect($this->Auth->redirect());
        } else {
            $this->Session->setFlash('Not able to login');
        }
    }

    public function logout() {
        $this->redirect($this->Auth->logout());
    }

}
+7

All Articles