浏览器关闭时 Omniauth 会话过期
在我的 Rails 3 应用程序中,我使用 Omniauth 进行用户身份验证部分 (fb/twitter)。
实际上我遵循这个:
https://github.com/RailsApps/rails3-mongoid-omniauth
https://github.com/RailsApps/rails3-mongoid-omniauth/wiki/Tutorial
但是, 当我关闭浏览器会话时,我需要再次登录。 如何为回访用户保留会话?
任何帮助将不胜感激!
In my rails 3 app I use Omniauth for the user authentication part (fb/twitter).
Actually I follow this:
https://github.com/RailsApps/rails3-mongoid-omniauth
https://github.com/RailsApps/rails3-mongoid-omniauth/wiki/Tutorial
But,
when I close the browser session expires and I need to login again.
How can I keep the session for returning users?
Any help would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你想要的并不难,你只需要在创建会话时设置一个永久cookie,然后在设置当前用户时检索这个值。
在您的
ApplicationController
中,只需将您的current_user
方法更改为:在您的
SessionsController
中,修改您的create
以设置cookie 如果用户想要:What you want is not difficult, you only have to set a permanent cookie when the session is created and then retrieve this value when you set the current user.
In your
ApplicationController
, just change yourcurrent_user
method to:And in your
SessionsController
, modify yourcreate
to set the cookie if user wants to:Devise 通过其 Rememberable 模块提供此功能。 OmniAuth 通过(您永远猜不到的)OmniAuth 模块轻松与其集成。甚至在您发布的第二个链接中也提到了!
Devise offers this functionality through its Rememberable module. OmniAuth integrates easily with it through the (you'd never guess it) OmniAuth module. It's even mentioned in the second link you posted!
请确保您的 Rails 应用程序遵循的 Cookie 策略确实具有适合您的用例的合理设置(请参阅上面我的评论中的链接)。我现在所能想象的(知道我所知道的,坐在我坐的地方)是 cookie 的属性在您的上下文中是次优/不可取的。
请检查浏览器调试/开发工具(例如 firebug、firecookie 或 chrome 开发工具)中的 cookie 设置。
抱歉,鉴于我对这个问题的了解,这就是我所能想到的。请随时再次与我联系,了解有关您的 cookie 和测试设置的更多详细信息。
我的2美分。
Please make sure the cookie policy that your rails app follows does have sensible settings for your use case (see the link in my comment above). All I can imagine right now (knowing what I know, sitting where I sit) is that the cookie(s) ha(s/ve) properties that are suboptimal/undesirable in your context.
Please check the cookie settings in a browser debug/development tool such as firebug, firecookie or the chrome development tools.
Sorry, that's all I can come up with given my knowledge of the problem. Feel free to contact me again with more details on your cookie- and testing-setup.
My 2Cents.
这是它对我的作用:
还有另一个方法来做到这一点
Here is how it works for me:
There is another way to do it