3

如果您在现有窗口中打开 Omniauth 的默认设置,它可以很好地工作,但不确定它在弹出上下文中如何工作,并且您正在通过 javascript 处理大部分交互

4

2 回答 2

15
var newwindow;
function login(provider_url, width, height) {
  var screenX     = typeof window.screenX != 'undefined' ? window.screenX : window.screenLeft,
      screenY     = typeof window.screenY != 'undefined' ? window.screenY : window.screenTop,
      outerWidth  = typeof window.outerWidth != 'undefined' ? window.outerWidth : document.body.clientWidth,
      outerHeight = typeof window.outerHeight != 'undefined' ? window.outerHeight : (document.body.clientHeight - 22),
      left        = parseInt(screenX + ((outerWidth - width) / 2), 10),
      top         = parseInt(screenY + ((outerHeight - height) / 2.5), 10),
      features    = ('width=' + width + ',height=' + height + ',left=' + left + ',top=' + top);

      newwindow = window.open(provider_url, 'Login', features);

  if (window.focus)
    newwindow.focus();

  return false;
}

将 provider_url 替换为 '/auth/facebook' 或 '/auth/twitter' 应该可以。

在您的回调网址中,

<script type="text/javascript">
  window.opener.location = '<%= @redirect_to %>';
  window.close();
</script>

您可以使用 @redirect_to 指向应刷新父窗口的页面来刷新页面。

于 2011-01-05T01:01:50.867 回答
3

好像可以自己做?

当用户单击“通过 facebook 登录”时 - 使用 JS 弹出一个位置为 /auth/facebook 的窗口。“回调”只会在同一窗口中路由回 /auth/callback。完成回调工作后,关闭当前窗口并刷新父窗口?

于 2010-12-05T21:31:38.113 回答