donglankui1263 2017-08-14 01:22
浏览 96
已采纳

更改基本HTTP身份验证领域和登录对话框消息

I want to change the message that pops up during implementation of Basic Auth.The current default message is:

enter image description here

Server requires a username and password.

Something that would be more accurate for me is :

Server requires an Email and Password.

My problem is that i can't find or don't know where this message is set and if it can be changed. Most of the questions online are about Basic Auth implemention but this is not my problem -- i can implement it very fine. I just need a more accurate response for the user.

Here is how i force an authentication window using echo:

c.Response().Header().Set(echo.HeaderWWWAuthenticate, `Basic realm="Your Email is your Username"`)
return echo.ErrUnauthorized

NB: Only Firefox shows the realm message. Both Chrome and Opera do not.

  • 写回答

2条回答 默认 最新

  • doufangpian5545 2017-08-17 02:46
    关注

    Thanks for the responses but they were not satisfactory. I had to do some reading on this topic.

    The correct answer is that the login prompt/dialog is a response built into the user-agent/browser and cannot be changed by the server. This also explains why some browsers show realm while others don't.

    According to Wikipedia Basic access authentication all the server does is:

    When the server wants the user agent to authenticate itself towards the server, it must respond appropriately to unauthenticated requests.

    Unauthenticated requests should return a response whose header contains a HTTP 401 Unauthorized status[4] and a WWW-Authenticate field.[5]

    The WWW-Authenticate field for basic authentication (used most often) is constructed as following:

    WWW-Authenticate: Basic realm="User Visible Realm"

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?