How to make Omniauth work with a popup?

By default, Omniauth works beautifully if you open it in an existing window, but don’t know how it works in a pop-up context, and you process most of the interactions through javascript

+3
source share
2 answers

Looks like you could do it yourself?

When the user clicks "Login via facebook" - use JS to open a window with the location / auth / facebook. The callback will simply return to / auth / callback in the same window. Once you have completed your work with a callback, close the current window and update the parent?

+3
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', .

URL-

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

, , @redirect_to , .

+15

Source: https://habr.com/ru/post/1778581/


All Articles