首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >删除特定操作的htpasswd保护

删除特定操作的htpasswd保护
EN

Stack Overflow用户
提问于 2018-02-15 06:33:05
回答 1查看 113关注 0票数 0

我有一个网站在cakephp 3与htpasswd保护。我想在没有密码的情况下访问特定的操作,例如/api/模型

我可以通过将以下代码放在webroot/..htaccess文件中,从特定文件中删除密码保护,但是如何实现cakephp 3中的特定操作。

代码语言:javascript
复制
<Files "test.php">
    Satisfy Any
</Files>
EN

回答 1

Stack Overflow用户

发布于 2018-02-17 14:20:04

我想如果我必须这么做的话,我会在控制器里做的。在cakephp中,我们可以很容易地选择身份验证选项,包括基本的auth。

代码语言:javascript
复制
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();
        }

    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48801179

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档