我搬到了omniauth-facebook,它工作的非常好。我一直在尝试使用弹出登录按钮,但我无法让它工作。Omniauth-Facebook:登录弹出窗口不重定向
我跟着https://github.com/mkdynamic/omniauth-facebook/blob/master/example/config.ru上的例子来了解rails应用程序。
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId : '#{ENV['APP_ID']}',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
oauth : true, // enable OAuth 2.0
xfbml : true // parse XFBML
});
};
(function(d) {
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
$(function() {
$('a').click(function(e) {
e.preventDefault();
FB.login(function(response) {
if (response.authResponse) {
$.get('/auth/facebook/callback');
}
}, { scope: '#{SCOPE}' });
});
});
</script>
<p>
<a href="#">Connect to FB</a>
</p>
它几乎工程:点击链接会显示弹出式窗口,我得到验证,但是当弹出关闭我留在登录页面上,即使我可以在目标页面处理的日志中看到,如果我点击一个可供客人和会员使用的链接,我将获得会员版本,这是登录工作的另一个证明。
那为什么即使登录成功,浏览器也不会重定向?我应该修改控制器方法中的某些内容(例如使用特殊格式的“respond_to”)来记录用户吗?
感谢
重定向在/ auth/facebook/callback(UserSessionsControler#create_with_provider)调用的控制器方法中。 – Nycen
这是一个ajax请求,它本身并不改变页面,它实际上很奇怪,因为你[从服务器获取某些东西](http://api.jquery.com/jQuery.get/),但是你的'不要做任何事情。 – ori
嗯,我想我会做一些事情,通过使用一个format.js和重定向的respond_to,但它不被调用,当我跟踪发生的事情时,它通过format.html。或者我应该呈现一个rjs视图来重新加载页面? – Nycen