dsjq62428 2015-08-09 13:09
浏览 47
已采纳

CakePHP 3删除WWW-authenticate

I am using CakePHP as a REST API for a single-page app.

Every request gets authenticated and authorized before proceeding.

The problem is, on logging in, if the credentials are wrong, Cake returns 401 and the browser shows its own server log in a popup.

I believe there is a way to stop it by unsetting the WWW-authenticate header, but I need to know how. Can someone explain how to unset that header?

  • 写回答

1条回答 默认 最新

  • doufei2355 2015-08-10 11:29
    关注

    The headers are being set in the \Cake\Auth\BasicAuthenticate authentication adapter.

    https://github.com/cakephp/cakephp/blob/3.0.11/src/Auth/BasicAuthenticate.php#L85-L110

    It's hardcoded, so if you want to change this behavior, you'll have to create a custom/extended authentication adapter and override this behavior.

    Here's a quick example:

    src/Auth/MyCustomBasicAuthenticate.php

    namespace App\Auth;
    
    use Cake\Auth\BasicAuthenticate;
    use Cake\Network\Exception\UnauthorizedException;
    use Cake\Network\Request;
    use Cake\Network\Response;
    
    class MyCustomBasicAuthenticate extends BasicAuthenticate
    {
        public function unauthenticated(Request $request, Response $response)
        {
            throw new UnauthorizedException();
        }
    }
    

    Controller

    $this->loadComponent('Auth', [
        'authenticate' => [
            'MyCustomBasic'
        ]
    ]);
    

    See also

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题