【问题标题】:Could not authenticate you from Foursquare because "Csrf detected"无法从 Foursquare 对您进行身份验证,因为“检测到 Csrf”
【发布时间】:2014-12-14 19:08:58
【问题描述】:

我在我的 Rails 应用程序中使用 Devise + Omniauth(实际上是 omniauth-foursquare,foursquare OAuth2 策略)。 登录后,我一直被重定向到我的应用 (/users/sign_in#=),并出现以下错误:

无法从 Foursquare 对您进行身份验证,因为“检测到 Csrf”

有什么见解吗?

这是我最后在控制台看到的:

  • 我,[2014-10-19T19:43:38.947771 #2] INFO -- omniauth:(foursquare)请求阶段已启动。
  • 于 2014 年 10 月 19 日 19:43:38 +0000 开始为 142.255.113... 获取“/users/auth/foursquare”
  • 参数:{"code"=>"2MZGM413...", "state"=>"1ba1cec3beb4..."}
  • Devise::SessionsController#new 作为 HTML 处理
  • 2014 年 10 月开始为 142.255.113... 获取“/users/auth/foursquare/callback?code=2MZGM413...&state=1ba1cec3beb4...”
  • 我,[2014-10-19T19:43:39.378477 #2] INFO -- omniauth: (foursquare) 回调阶段已启动。
  • E,[2014-10-19T19:43:39.378660 #2] 错误 --omniauth: (foursquare) 身份验证失败! csrf_detected: OmniAuth::Strategies::OAuth2::CallbackError, csrf_detected |检测到 CSRF

据我所知,当我收到“cookie 溢出”错误并切换到 session_storing 时,我的麻烦就开始了:(session_store.rb)

Rails.application.config.session_store :active_record_store, key: '_APPNAME_session', domain: 'DOMAIN.com'

谢谢!

【问题讨论】:

    标签: ruby-on-rails omniauth csrf foursquare


    【解决方案1】:

    如果您检查应用程序的源代码,您会看到生成的 HTML 在 HEAD 元素中包含 CSRF 元标记(即 csrf-token 和 csrf-param)。最有可能的是,您的布局/视图之一正在调用 csrf_meta_tags 方法。尝试删除它以查看它是否有效,然后考虑为不需要它的表单创建一个没有它的单独布局。其他在前端 Rails 方面有更多经验的人可以在这里提出最佳实践。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-16
      • 1970-01-01
      • 2011-08-04
      • 1970-01-01
      • 1970-01-01
      • 2013-02-15
      • 2021-04-14
      相关资源
      最近更新 更多