返回HTTP 401状态AJAX响应,而WWW身份验证

编程入门 行业动态 更新时间:2024-10-25 17:17:27
本文介绍了返回HTTP 401状态AJAX响应,而WWW身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否确定返回 HTTP 401 的,如果你想表达的是没有登录用户,即使登录机制是基于表单的,而不是一个AJAX调用的响应状态基于HTTP(基本,摘要等。)?

Is it OK to return an HTTP 401 status for a response to an AJAX call if you wish to convey that the user is not logged in, even though the login mechanism is form-based and not HTTP based (Basic, Digest, etc.)?

答案在这里建议401应使用: stackoverflow/a/6937030/2891365

The answer here suggests that 401 should be used: stackoverflow/a/6937030/2891365

和这篇文章显示某人使用401 Ajax响应的一个实际的例子:www.bennadel/blog/2228-some-thoughts-on-handling-401-unauthorized-errors-with-jquery.htm

And this post shows an actual example of someone using 401 for an AJAX response: www.bennadel/blog/2228-some-thoughts-on-handling-401-unauthorized-errors-with-jquery.htm

然而, RFC 2616 HTTP / 1.1 明确指出,一个特殊的头是必要的,言下之意的,它只能被用于HTTP认证

However, RFC 2616 for HTTP/1.1 clearly states that a special header is necessary, implying that it can only be used for HTTP authentication.

10.4.2 401未经授权

请求要求用户身份验证。响应必须包含一个 WWW验证 的包含适用于请求的资源是一个挑战头域(第14.47)。

The request requires user authentication. The response MUST include a WWW-Authenticate header field (section 14.47) containing a challenge applicable to the requested resource.

我想我或许可以发送一个伪造的标题如 WWW验证:Web窗体,并且仍然符合W3C规范,但感觉像它违反了 WWW验证头。

I guess I can probably send a bogus header like WWW-Authenticate: WebForm and still conform to W3C specs but it feels like it's violating the spirit of the WWW-Authenticate header.

在最后,我似乎无法找到明确规定HTTP 401是否允许AJAX响应的权威来源。有没有办法,我错过了这个权威渠道?

In the end, I cannot seem to find an authoritative source that explicitly states whether HTTP 401 is allowed for AJAX responses. Is there an authoritative source on this that I missed?

推荐答案

我会说这是不正常,因为401是告诉客户端提供的HTTP身份验证凭据。适当的反应将是403禁止,只是告诉客户这是不允许访问资源,无论出于何种原因。

I would say it's not ok since 401 is for telling the client to provide http authentication credentials. The proper response would be 403 Forbidden, simply telling the client it's not allowed to access the resource, for whatever reason.

更多推荐

返回HTTP 401状态AJAX响应,而WWW身份验证

本文发布于:2023-11-26 16:48:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634424.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:身份验证   状态   HTTP   AJAX   WWW

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!