gpt4 book ai didi

java - 在 RESTful web 服务中实现注销

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:03:01 24 4
gpt4 key购买 nike

我正在开发一个需要注销服务的移动应用程序。登录服务是通过从数据库验证来完成的,现在我被困在注销状态。

最佳答案

退一步

您没有提供很多关于如何在您的应用程序中执行身份验证的详细信息,因此很难猜测您在做什么。

但是,需要注意的是,在 REST 应用程序中,不得在服务器端存储 session 状态。相反, session 状态必须完全由客户端处理

但是服务器端的 session 有什么问题呢?它们是有状态的并且它们破坏了 REST stateless constraint (继续阅读以获取更多详细信息),因此它不是 REST。

无状态约束

根据 Roy T. Fielding 的 dissertation , 休息 stateless constraint定义如下:

5.1.3 Stateless

[...] each request from client to server must contain all of the information necessary to understand the request, and cannot take advantage of any stored context on the server. Session state is therefore kept entirely on the client. [...]

例如,当访问需要身份验证的 protected 资源时,每个请求都必须包含所有必要的数据以进行正确的身份验证/授权。认证数据应属于标准 HTTP Authorization header 。来自RFC 7235 :

4.2. Authorization

The Authorization header field allows a user agent to authenticateitself with an origin server -- usually, but not necessarily, afterreceiving a 401 (Unauthorized) response. Its value consists ofcredentials containing the authentication information of the useragent for the realm of the resource being requested. [...]

总结

REST 是无状态的。在 session 的意义上没有登录或注销。每个针对需要身份验证的资源的请求都必须携带身份验证数据。并且 session 状态保存在客户端而不是服务器。

关于java - 在 RESTful web 服务中实现注销,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37188212/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com