我正在尝试按照 Railscast #360 中的描述实现omniauth-facebook,但遇到了很大的障碍。当我单击登录链接时,我会收到所需的弹出窗口,要求我输入我的 Facebook 凭据,但是当我提交时,我收到 OmniAuth::Strategies::OAuth2::CallbackError 错误。在 apache 日志中,会打印以下内容:(facebook) Authentication failure!invalid_credentials:OmniAuth::Strategies::OAuth2::CallbackError,OmniAuth::Strategies::OAuth2::CallbackError
这是相关代码:
全域认证.rb
OmniAuth.config.logger = Rails.logger
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_SECRET']
end
session_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
应用程序.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>
我错过了一些简单的东西吗?最近几天我一直在寻找解决方案。