Vee
Vee

Reputation: 1841

Getting Facebook Authentication Dialog to redirect to the original browser window running my application

I'm really new to the Facebook API and am having trouble getting the Facebook authentication dialog to redirect to the original browser window of my application. Here's the current process via client-side flow:

  1. User is logged into my application (Ruby on Rails Application with Javascript/Jquery scripting).

  2. User clicks on button in my application to log into his/her Facebook account.

  3. The Facebook Authentication Dialog pops up in a 2nd window, asking user to log in.

  4. User logs into Facebook

  5. The Facebook Authentication Dialog asks the user if he/she wants to grant my application permission.

  6. User clicks ok to share profile information.

  7. The Facebook Authentication Dialog redirects the 2nd window to also open an instance of my application with the access token in the URL.

My questions are the following:

  1. How can I get Facebook Authentication Dialog window to close after the user successfully logs into his/her Facebook account?

  2. How can I gain access to the Facebook Access token after closing the second window?

The best way to illustrate what I'm ultimately trying to do is when somebody is signing into ESPN's site (1st window). Notice, that a modal window (2nd window) opens where you can click "sign in" (upper right corner) on ESPN's site. In this modal window, you can sign in with your Facebook account. Clicking on the "Sign in with Facebook Account" link will open a 3rd window which will take you through the Facebook Authentication process. When finished with signing into Facebook, the 3rd window will close and the modal window is updated based on the status of the 3rd window that closed.

How can I get the Facebook Authentication Dialog window to close and redirect to a preceding window?

Thanks!

Upvotes: 0

Views: 1415

Answers (1)

Brian Glaz
Brian Glaz

Reputation: 15696

Here is what I did in a similar situation. For the facebook dialog, have it redirect to a page on your site then simply grabs the access token and whatever other data you need. (In my case I just sessionized some of the user info). In the output of that page, include some javascript in your document.ready that will close this second window, and redirect to whatever page you want in the first window. It looks somthing like this.

window.opener.location.href = '/redirect_url_for_first_window'; //set url of the main window
window.close(); //close the popup

You can use window.opener in a popup window to refer to the window it came from. You can even have your popup window access variables and call functions of the main window as well.

Hope this helps!

Upvotes: 2

Related Questions