http-authentication - 身份验证 token 到期的正确 HTTP 代码 - 401 或 403?

标签 http-authentication

401 似乎用于表示身份验证失败,而 403 表示授权失败(这意味着身份验证成功?)
在 oauth 流的情况下,如果我尝试使用过期的 token 进行身份验证,提示客户端刷新 token 并重试的正确错误代码是什么?

最佳答案

A 401。401 与 403 的混淆并不新鲜。请参阅 w3.org 电子邮件中的一些讨论:https://lists.w3.org/Archives/Public/ietf-http-wg/2008AprJun/0418.html ,尽管引用的 RFC 2616 已过时。

关于 401,见 https://tools.ietf.org/html/rfc7235#section-3.1

关于 403,见 https://tools.ietf.org/html/rfc7231#section-6.5.3

从 401 描述中,虽然“有效”有待解释:

The 401 (Unauthorized) status code indicates that the request has not been applied because it lacks valid authentication credentials for the target resource.



但更相关的是,请参阅关于承载 token 身份验证的 RFC 6750,第 3 节,最后一段。
https://tools.ietf.org/html/rfc6750#section-3

And in response to a protected resource request with an authentication attempt using an expired access token:


 HTTP/1.1 401 Unauthorized
 WWW-Authenticate: Bearer realm="example",
                   error="invalid_token",
                   error_description="The access token expired"

关于http-authentication - 身份验证 token 到期的正确 HTTP 代码 - 401 或 403?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45153773/

相关文章:

php - Wowza 服务器上的 PHP 脚本的 HTTP 身份验证失败?

session - 如何使用 angular-http-auth 保持 session ?

java - 授权用户读取 URL 正文内容时出错

authentication - 了解跨域用户认证

我可以让 libcurl 记住请求之间的 HTTP 摘要身份验证状态吗?

Python请求收到404,wget获取正确页面

java - 使用 Apache HTTP 组件的 HTTP 身份验证 : force sending of challenge

http - http ://user:pass@host. com 身份验证如何工作?

java - Jersey 客户端过滤器线程安全

IIS 作为反向代理