ruby-on-rails – Omniauth-facebook保持报告invalid_credentials

我试图实现omniauth-facebook如所描述的Railscast#360,并遇到了相当一个路障。当我点击登录链接,我得到所需的弹出窗口要求输入我的Facebook凭据,但当我提交,我得到一个OmniAuth :: Strategies :: OAuth2 :: CallbackError错误。在apache日志,这是打印:(Facebook)身份验证失败! invalid_credentials:OmniAuth :: Strategies :: OAuth2 :: CallbackError,OmniAuth :: Strategies :: OAuth2 :: CallbackError

这里是相关代码:

omn​​iauth.rb

OmniAuth.config.logger = Rails.logger

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_SECRET']
end

sessions_controller.rb

class SessionsController < ApplicationController
  def create
    user = User.from_omniauth(env["omniauth.auth"])
    session[:user_id] = user.id
    redirect_to root_url
  end

  def destroy
    session[:user_id] = nil
    redirect_to root_url
  end
end

application.html.erb

<div id="fb-root"></div>
<script>        
window.fbAsyncInit = function() {
    FB.init({
        appId      : '(**my app id**)', // App ID
        status     : true, // check login status
        cookie     : true // enable cookies to allow the server to access the session
    });

    $('#sign_in').click(function(e) {
        e.preventDefault();
        return FB.login(function(response) {
            if (response.authResponse) {
                return window.location = '/auth/facebook/callback';
            }
        });
    });

    return $('#sign_out').click(function(e) {
        FB.getLoginStatus(function(response) {
            if (response.authResponse) {
                return FB.logout();
            }
        });
        return true;
    });
};
 </script>

我缺少一些简单的东西吗?我一直在寻找最近几天的解决方案。

看起来像omniauth-facebook v1.4.1介绍了CSRF的问题。临时修复是只回滚到v1.4.0。在您的Gemfile中,将omniauth-facebook行更改为:

gem 'omniauth-facebook', '1.4.0'

我报告了问题:https://github.com/mkdynamic/omniauth-facebook/issues/73

http://stackoverflow.com/questions/11597130/omniauth-facebook-keeps-reporting-invalid-credentials

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:ruby-on-rails – Omniauth-facebook保持报告invalid_credentials