我有一个网站在cakephp 3与htpasswd保护。我想在没有密码的情况下访问特定的操作,例如/api/模型
我可以通过将以下代码放在webroot/..htaccess文件中,从特定文件中删除密码保护,但是如何实现cakephp 3中的特定操作。
<Files "test.php">
Satisfy Any
</Files>发布于 2018-02-17 14:20:04
我想如果我必须这么做的话,我会在控制器里做的。在cakephp中,我们可以很容易地选择身份验证选项,包括基本的auth。
class AppController extends Controller
{
public function initialize() {
parent::initialize();
$this->loadComponent('Auth', [
'authenticate' => [
'Basic' => [
'fields' => [
// username and password from database
'username' => 'email',
'password' => 'password'
],
],
],
'storage' => 'Memory',
'unauthorizedRedirect' => false
]);
/**
* Allowed actions
* ['Controller' => ['method' => 1, 'method' => 1]]
*/
$excluded_actions = [
'Users' => [
'index' => 1,
'edit' => 1
]
];
$controller = $this->request->getParam('controller');
$method = $this->request->getParam('action');
if(isset($excluded_actions[$controller]) && isset($excluded_actions[$controller][$method])) {
$this->Auth->allow();
}
}
}https://stackoverflow.com/questions/48801179
复制相似问题