Ruby on Rails - 如何在omniauthable设备中处理过时的访问令牌?

发布于 2024-12-14 04:45:19 字数 37 浏览 5 评论 0原文

当用户的访问令牌过时并从而将用户注销时,如何在设备中检测到?

How do I detect in devise when the user's access tokens are stale and thus logging the user out?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花海 2024-12-21 04:45:20

为什么需要这个?有 timeoutable 选项允许跟踪会话超时。我可能是错的,但令牌是有时间存在的 cookie 键,并且由浏览器跟踪。来自设计(钩子):

每次设置记录时,我们都会检查其会话是否已超时
或不,基于上次请求时间。如果是这样,该记录将被注销并
重定向到登录页面。此外,每次请求到来时,
设置记录后,我们将其范围会话内的最后一个请求时间设置为
验证以下请求中的超时。

---- 更新(不要放入太大的commets)---

在大多数情况下,当您使用登录时,不需要从外部服务获取身份验证。因此,在用户登录的情况下(即存在会话 cookie 并且会话有效),同时她从外部服务注销,这意味着她可以使用您的网站,直到您的会话结束。过期。同样,一旦用户需要身份验证,就会使用外部服务。因此,当您网站上的会话过期并且用户尝试使用外部服务登录时,她将被重定向到她将登录的外部网站(如果已经登录,则不会)。然后,外部服务重定向回您的站点提供的回调(在大多数情况下,路径是 /auth/:provider/callback),您的控制器(或由 devise 提供的默认值)将在需要时创建一个用户和一个为他举行会议。

Why do you need this? There is timeoutable option exist that allows to track session timeout. I might be wrong, but tokens are cookies keys that have time to live and they are tracked by browser. From Devise (hooks):

Each time a record is set we check whether its session has already timed out
or not, based on last request time. If so, the record is logged out and
redirected to the sign in page. Also, each time the request comes and the
record is set, we set the last request time inside it's scoped session to
verify timeout in the following request.

---- UPDATE (to not put in commets as its large)---

In the most cases, when you use is logged in, there is no requirements to get authentication from external servises. So in the cases when user is logged in (i.e. session cookie present and session is valid), and in the same time she logs out from external servise that means that she can use your site until your session is expires. Again, the external service is used once user requires authentication. So when session is expired on your site and user trying to log in using external service she will be redirected to external site where she will log in (or not if already). Then external service redirects back to your site provided callback (in the most cases path is /auth/:provider/callback) where your controller (or default provided by devise) will create if required an user and a session for him.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文