"email not verified" 的 HTTP 状态
HTTP status for "email not verified"
我已经看到了所有 HTTP 状态代码的列表。
但是对我来说,似乎没有 "email not verified" 的代码(用于 authentication/authorization)。
你有过同样的"problem"吗?您使用了什么 HTTP 状态代码?
我想它应该是一个以 4 开头的代码,因为它是 "client error"。
状态码4xx
class适用于客户端似乎出错的情况:
The 4xx
(Client Error) class of status code indicates that the client
seems to have erred. Except when responding to a HEAD
request, the
server SHOULD send a representation containing an explanation of the
error situation, and whether it is a temporary or permanent
condition. These status codes are applicable to any request method.
User agents SHOULD display any included representation to the user.
对于 authentication 和 authorization,401
和 403
是要使用的正确状态代码,分别。无论状态代码如何,您都应该始终在响应负载中描述错误原因。
401
未经授权
将此状态代码用于 HTTP 身份验证 问题,即无效凭据。
The 401
(Unauthorized) status code indicates that the request has not
been applied because it lacks valid authentication credentials for
the target resource. The server generating a 401
response MUST send
a WWW-Authenticate
header field containing at least one
challenge applicable to the target resource.
If the request included authentication credentials, then the 401
response indicates that authorization has been refused for those
credentials. The user agent MAY repeat the request with a new or
replaced Authorization
header field. If the 401
response contains the same challenge as the prior response, and the
user agent has already attempted authentication at least once, then
the user agent SHOULD present the enclosed representation to the
user, since it usually contains relevant diagnostic information.
403
禁止
将此状态代码用于 授权 问题,即凭据有效但不足以授予访问权限。
The 403
(Forbidden) status code indicates that the server understood
the request but refuses to authorize it. A server that wishes to
make public why the request has been forbidden can describe that
reason in the response payload (if any).
If authentication credentials were provided in the request, the
server considers them insufficient to grant access. The client
SHOULD NOT automatically repeat the request with the same
credentials. The client MAY repeat the request with new or different
credentials. However, a request might be forbidden for reasons
unrelated to the credentials. [...]
虽然 CodeCaster 提供了一个非常明确的答案作为评论,但正确的是有时不合适。
首先,您会发现规范中没有提及 电子邮件地址。同样,也没有提及鞋码、模型铁路轨距、狗的品种或许多其他内容。它与 HTTP 无关。这只是一个数据项。
您似乎有一些与您用于身份验证目的的数据项相关联的状态 - 但没有提供对该状态的任何解释,也没有提供它是如何应用的。我假设您的意思是“未验证”状态意味着数据项与与您的站点交互的用户之间的唯一关联是用户的断言。此外,您不允许用户以此作为令牌进行身份验证。
我在这里似乎很迂腐 - 但对于“电子邮件未验证”还有其他有效的解释。您应该在问题中提供更多信息。
您的故事中还有一个空白:我们要处理的是哪个请求?同样,我冒昧地假设该请求是尝试进行身份验证。
在这种情况下,请求没有本质上的错误。客户本质上没有任何问题。服务器本质上没有任何问题。不允许用户进行身份验证是基于数据的策略决定。
您的问题中缺少的另一个关键信息是实际发出请求的原因。如果它是浏览器发送的表单,那么默认情况下,return将 200 OK(或 204,或重定向到 200)以外的任何内容发送到 MSIE 都会导致浏览器显示内部消息和 不是您发送的内容。
OTOH 如果客户端是用户设备上的应用程序 运行 或 Ajax 请求,那么您可以控制 API 并可以定义自己的语义。如果你想return一个692状态码来表示这种情况,那么你可以return一个692错误码。您甚至可以在响应中插入您自己的 headers(按照惯例,这些应该以 'X-' 开头)。
在定义的状态下验证失败。但是 return401 响应将提示浏览器尝试 HTTP 身份验证 - 这不能解决问题。
恕我直言,最接近的现有代码是 403 或 422。但根据您提供的信息,我无法确定您是否应该使用。
我已经看到了所有 HTTP 状态代码的列表。 但是对我来说,似乎没有 "email not verified" 的代码(用于 authentication/authorization)。 你有过同样的"problem"吗?您使用了什么 HTTP 状态代码?
我想它应该是一个以 4 开头的代码,因为它是 "client error"。
状态码4xx
class适用于客户端似乎出错的情况:
The
4xx
(Client Error) class of status code indicates that the client seems to have erred. Except when responding to aHEAD
request, the server SHOULD send a representation containing an explanation of the error situation, and whether it is a temporary or permanent condition. These status codes are applicable to any request method. User agents SHOULD display any included representation to the user.
对于 authentication 和 authorization,401
和 403
是要使用的正确状态代码,分别。无论状态代码如何,您都应该始终在响应负载中描述错误原因。
401
未经授权
将此状态代码用于 HTTP 身份验证 问题,即无效凭据。
The
401
(Unauthorized) status code indicates that the request has not been applied because it lacks valid authentication credentials for the target resource. The server generating a401
response MUST send aWWW-Authenticate
header field containing at least one challenge applicable to the target resource.If the request included authentication credentials, then the
401
response indicates that authorization has been refused for those credentials. The user agent MAY repeat the request with a new or replacedAuthorization
header field. If the401
response contains the same challenge as the prior response, and the user agent has already attempted authentication at least once, then the user agent SHOULD present the enclosed representation to the user, since it usually contains relevant diagnostic information.
403
禁止
将此状态代码用于 授权 问题,即凭据有效但不足以授予访问权限。
The
403
(Forbidden) status code indicates that the server understood the request but refuses to authorize it. A server that wishes to make public why the request has been forbidden can describe that reason in the response payload (if any).If authentication credentials were provided in the request, the server considers them insufficient to grant access. The client SHOULD NOT automatically repeat the request with the same credentials. The client MAY repeat the request with new or different credentials. However, a request might be forbidden for reasons unrelated to the credentials. [...]
虽然 CodeCaster 提供了一个非常明确的答案作为评论,但正确的是有时不合适。
首先,您会发现规范中没有提及 电子邮件地址。同样,也没有提及鞋码、模型铁路轨距、狗的品种或许多其他内容。它与 HTTP 无关。这只是一个数据项。
您似乎有一些与您用于身份验证目的的数据项相关联的状态 - 但没有提供对该状态的任何解释,也没有提供它是如何应用的。我假设您的意思是“未验证”状态意味着数据项与与您的站点交互的用户之间的唯一关联是用户的断言。此外,您不允许用户以此作为令牌进行身份验证。
我在这里似乎很迂腐 - 但对于“电子邮件未验证”还有其他有效的解释。您应该在问题中提供更多信息。
您的故事中还有一个空白:我们要处理的是哪个请求?同样,我冒昧地假设该请求是尝试进行身份验证。
在这种情况下,请求没有本质上的错误。客户本质上没有任何问题。服务器本质上没有任何问题。不允许用户进行身份验证是基于数据的策略决定。
您的问题中缺少的另一个关键信息是实际发出请求的原因。如果它是浏览器发送的表单,那么默认情况下,return将 200 OK(或 204,或重定向到 200)以外的任何内容发送到 MSIE 都会导致浏览器显示内部消息和 不是您发送的内容。
OTOH 如果客户端是用户设备上的应用程序 运行 或 Ajax 请求,那么您可以控制 API 并可以定义自己的语义。如果你想return一个692状态码来表示这种情况,那么你可以return一个692错误码。您甚至可以在响应中插入您自己的 headers(按照惯例,这些应该以 'X-' 开头)。
在定义的状态下验证失败。但是 return401 响应将提示浏览器尝试 HTTP 身份验证 - 这不能解决问题。
恕我直言,最接近的现有代码是 403 或 422。但根据您提供的信息,我无法确定您是否应该使用。