使用 facebooker 检查 FB Connect 会话是否过期

发布于 2024-08-06 04:42:51 字数 252 浏览 2 评论 0原文

如何使用rails facebooker插件检查FB Connect会话是否仍然有效?是否有任何帮助程序或模块可以检查会话?我发现如果我在浏览器中打开 2 个选项卡,一个使用 facebook 登录,另一个使用我的网站并使用 FB Connect 登录。当用户尝试在我的网站中注销时,facebook将删除两个cookie,但是当用户通过facebook注销时,它只会删除facebook网站中的cookie,因此我网站中的cookie仍然保留,我需要检查cookie是否仍然有效或不...

how to check whether FB Connect session is still valid or not using rails facebooker plugin ? Are there any helper or module that can check the session ? I figure out that if I open up 2 tab in browser, one login with facebook, another is with my site and login using FB Connect. When user trying to logout in my site, facebook will erase both cookie, but when user logout through facebook, it will erase cookie in facebook site only, so the cookie in my site still left behind and I need to check whether the cookie still valid or not...

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

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

发布评论

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

评论(3

美羊羊 2024-08-13 04:42:51

使用Facebooker,当你尝试使用异常时,你会得到一个异常,可以在application.rb中rescue_from'd

rescue_from Facebooker::Session::SessionExpired, :with => :facebook_session_expired

def facebook_session_expired
  clear_fb_cookies!
  clear_facebook_session_information
  reset_session # remove your cookies!
  flash[:error] = "Your facebook session has expired."
  redirect_to root_url
end

Using Facebooker, you'll get an exception when you try to use the exception, which can be rescue_from'd in application.rb

rescue_from Facebooker::Session::SessionExpired, :with => :facebook_session_expired

def facebook_session_expired
  clear_fb_cookies!
  clear_facebook_session_information
  reset_session # remove your cookies!
  flash[:error] = "Your facebook session has expired."
  redirect_to root_url
end
失眠症患者 2024-08-13 04:42:51

我还不能投票,但添加这行的答案

page.redirect_to url

是正确的。如果 Mike 正在阅读,我建议将其添加到 Facebooker。

I can't upvote things yet, but the answer that adds the line:

page.redirect_to url

is correct. I'd recommend adding it to Facebooker if Mike is reading.

孤独难免 2024-08-13 04:42:51

当 Facebook 会话无效时,fb_logout_link 方法不会重定向。将重定向回调添加到您的 logout_path 中,它将为您完成这项工作。

    def fb_logout_link(text,url,*args)
      js = update_page do |page|
        page.call "FB.Connect.logoutAndRedirect",url
        # When session is valid, this call is meaningless, since we already redirect
        # When session is invalid, it will log the user out of the system.
        page.redirect_to url # You can use any *string* based path here
      end
      link_to_function text, js, *args
    end

The fb_logout_link method does not redirect when Facebook session is invalid. Add a redirect callback to your logout_path and it will do the job for you.

    def fb_logout_link(text,url,*args)
      js = update_page do |page|
        page.call "FB.Connect.logoutAndRedirect",url
        # When session is valid, this call is meaningless, since we already redirect
        # When session is invalid, it will log the user out of the system.
        page.redirect_to url # You can use any *string* based path here
      end
      link_to_function text, js, *args
    end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文