How to open facebook login form in pop up box while sign in with facebook
I am implementing sign in with Facebook in my web application. I am using omniauth gem for it. I want to open lo开发者_高级运维gin to facebook form in new pop up. How can I do that? Please help.
I'm assuming that you have OmniAuth working in general, and are only curious about how to do it in a new window. If you haven't set up OmniAuth yet, there's a great RailsCast about it here.
OmniAuth shouldn't have any problems with working in a pop-up out of the box. To start with, just include target='_blank'
on your login page, like so:
<%= link_to "Log in with Facebook", "/auth/facebook", :target => '_blank' %>
This should load the Facebook authorization page in a new window, and you should be able to get through the entire OAuth process. Once you've finished OAuth, however, you will need to render a template that includes some javascript to handle closing of the page. Here's the pattern we follow:
<script language='javascript'>
if (opener.authenticationSuccessful) {
opener.authenticationSuccessful();
} else {
opener.location.href = "<%= root_path %>"; // your 'login path'
}
window.close();
</script>
This works well for us, since it allows us to override the default behavior (go to the root login page) on a page by page basis (for instance, if someone is only adding an authentication to an existing session), but by default, will do what you expect without any additional work.
精彩评论