简体   繁体   English

浏览器为后续请求发送旧的“授权”标头

[英]Browser sending old "Authorization" header for subsequent requests

We are experiencing an issue with Browser sending Authorization header of initial request for subsequent requests to the same requestURI.我们遇到了一个问题,即浏览器将初始请求的Authorization标头发送到同一 requestURI 的后续请求。

Problem:问题:

We have a webproject which has user specific business logic so we have this login logic where for the initial request, if we don't have a existing session we send a 401 response along with WWW-Authenticate: Basic realm="production site" header to get credentials via the client and the browser issues a rerequest with the Authorization header and we use it to create a sesssion and initiate the login process.我们有一个具有用户特定业务逻辑的 Web 项目,所以我们有这个登录逻辑,用于初始请求,如果我们没有现有会话,我们会发送 401 响应以及WWW-Authenticate: Basic realm="production site"标头通过客户端获取凭据,浏览器使用Authorization标头发出重新请求,我们使用它来创建会话并启动登录过程。

But however, once the browser cache & cookies are cleared the session gets destroyed but we are still getting the old(Got from the initial request) Authorization header sent to that URI.但是,一旦浏览器缓存和 cookie 被清除,会话就会被破坏,但我们仍然会收到发送到该 URI 的旧(从初始请求中获取) Authorization标头。

We susupect it was cache issue but not sure.我们怀疑这是缓存问题但不确定。

Can someone please help us to understand whats happening here and why we are getting the same Authorization header everytime.有人可以帮助我们了解这里发生的事情以及为什么我们每次都获得相同的Authorization标头。 Thanks in advance.提前致谢。

Basic/Digest authentication usually gets stored separate from the cache and is unrelated to cookies.基本/摘要身份验证通常与缓存分开存储,并且与 cookie 无关。

The server doesn't have a ton of control over this, but one way to force the browser to clear credentials is to just send a 401 with a new WWW-Authenticate header (even if the credentials you got are correct, you basically need some way to track that the intent was to log out), but this will create a new login dialog that the user will need to dismiss.服务器对此没有太多控制,但是强制浏览器清除凭据的一种方法是只发送一个带有新 WWW-Authenticate 标头的 401(即使您获得的凭据是正确的,您基本上需要一些跟踪意图是注销的方法),但这创建一个新的登录对话框,用户需要关闭该对话框。

I'd recommend not mixing cookies and HTTP Authorization.我建议不要混合使用 cookie 和 HTTP 授权。 You don't need sessions because you already know who's making the request.您不需要会话,因为您已经知道谁在发出请求。

Generally HTTP Auth in browsers kinda sucks and browser developers have not done a good job creating a good UX for this, which is why almost everyone just renders HTML login forms instead.一般来说,浏览器中的 HTTP Auth 有点糟糕,浏览器开发人员并没有为此创建良好的用户体验,这就是为什么几乎每个人都只呈现 HTML 登录表单的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM