Yono
Yono

Reputation: 23

Using Facebook API in widget

I'm building a widget that can be placed on a various sites, and will have users be able to log in via facebook connect to accounts on the widget's parent site. I was going to use the Facebook JS SDK to do this, but the widget will likely be placed on sites that already have the FB JS SDK initialized on them with a different app ID, and if I were to run code this way it could lead to a namespace problem.

The only current solution I have come up with is to do the server-side type authorization, and have a redirect-url that leads back to the current page in which the widget is hosted and use the state paremeter to alert backbone router that the user has logged in.

The first problem I thought of is that on the facebook docs site it says

For security, the redirect_uri must have the same base domain as that specified in the App Domain property of your app's settings, or be a URL of the form https://apps.facebook.com/YOUR_APP_NAMESPACE.

How do I bring people back to the original page that the widget it hosted on after login? Is there a better approach to this problem?

Upvotes: 0

Views: 203

Answers (1)

ekeren
ekeren

Reputation: 3458

you can use Server side authentication and redirect_uri to your site that will redirect to the various site

redirect_uri = https://www.mydomain.com/?r=https%3A%2F%2Fwww.somesite.me

On you server you will look of the query param r and redirect the request to r value.

You can also do your own authentication for users (when they first sign in) and store there facebook access_token on you DB, once your widget is running (under https) and you identified the user on your authentication you can send the widget client the user's access_token and work with it.

You can even create your own Simple FB-like ajax library, for most things it will be a simple get/post/put calls with access_token as a url parameter

Hopes it helps

Upvotes: 1

Related Questions