Хотя вы можете создать собственный класс аутентификации, я понятия не имею, использовать ли его, кроме изучения поведения внутреннего.
// Controller/Component/Auth/CustomBasicAuthenticate.php
class CustomBasicAuthenticate {
public function authenticate(CakeRequest $request, CakeResponse $response) {
return true;
}
public function getUser($request) {
if (env('PHP_AUTH_USER') === 'foo' && env('PHP_AUTH_PW') === 'bar') {
return array(
'User' => array(
'id' => '1', 'username' => 'foo', 'password' => 'bar'
)
);
} else {
return false;
}
}
public function unauthenticated(CakeRequest $request, CakeResponse $response) {
$response->statusCode('401');
$response->header('WWW-Authenticate: Basic realm="My Realm"');
$response->body('fail');
$response->send();
}
}
// Controller/HelloController.php
class HelloController extends AppController {
public $autoRender = false;
public $uses = array('User');
public $components = array(
'Auth' => array(
'loginAction' => array(
'controller' => 'hello',
'action' => 'index',
),
'authenticate' => array(
'CustomBasic' => array('userModel' => 'User')
)
)
);
public function index() {
echo 'ok';
}
}