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 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目