CSRF 在刷新网页上检测到错误消息

NIk*_*and 5 ruby-on-rails protect-from-forgery facebook-graph-api omniauth-facebook ruby-on-rails-5

我正在开发一个从 facebook 获取详细信息的 Rails 应用程序。我已经从 facebook 获取了详细信息。但是当我刷新网页时,我收到了一个名为 CSRF 检测到的错误。我用过一些方法,但都失败了。

facebook Graph API 用于编辑操作。

这些是在员工控制器的内部类中添加的。

  1. skip_before_action :verify_authenticity_token

  2. skip_before_action :verify_authenticity_token, only: [:edit]

  3. protect_from_forgery :only => [:edit]

  4. skip_before_action :authenticate_user, only: [:edit]

  5. skip_before_action :authenticate_user!

当使用 authentication_user 时(第 4 和第 5 种情况)我收到一个参数错误, Before process_action callback :authenticate_user has not been defined .

在所有其他情况下,使用 facebook 更新页面后刷新页面时的错误是 OmniAuth::Strategies::OAuth2::CallbackError

csrf_detected | CSRF detected

PS:我使用了 'omniauth-facebook' 和 'koala' gem 进行集成。

小智 2

我之前遇到过这个问题,我之前尝试过验证真实性令牌,但只有在重定向页面时才有效,所以我请求您重定向页面。