简体   繁体   English

如何让Omniauth使用弹出窗口?

[英]How to make Omniauth work with a popup window?

如果你在现有窗口中打开Omniauth,默认情况下效果很好,但不知道它在弹出上下文中是如何工作的,你通过javascript处理大部分交互

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;
}

Replace provider_url with '/auth/facebook' or '/auth/twitter' should work. 将provider_url替换为'/ auth / facebook'或'/ auth / twitter'应该有效。

At your callback url, 在你的回调网址,

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

You can refresh the page however you want with @redirect_to pointing to the page where your parent window should be refreshed to. 您可以使用@redirect_to指向要将父窗口刷新到的页面随意刷新页面。

Seems like you could do this yourself? 好像你自己可以做到这一点?

When user clicks 'login via facebook' - use JS to pop open a window with a location of /auth/facebook. 当用户点击“通过Facebook登录”时 - 使用JS弹出一个位置为/ auth / facebook的窗口。 The 'callback' will just route back to /auth/callback in this same window. 'callback'将在同一窗口中返回/ auth / callback。 Once you've done your work with the callback, close the current window and refresh the parent? 使用回调完成工作后,关闭当前窗口并刷新父级?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM