Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook login with multiple domains

Tags:

facebook

I know that facebook allow me to specify multiple domains for my app. I can specify multiple App Domains

But in the "Website with Facebook Login" i can only specify one url. I can only specify one Site URL

Is it possible for me, to authenticate users on domain.se, domain.dk and domain.net with the same App ? Or should i still create one app, for each domain ?

like image 630
mnstrflkrn Avatar asked Sep 06 '12 08:09

mnstrflkrn


People also ask

Can you verify multiple domains on Facebook?

Click on the Add button, and enter your domain in the Add a Domain pop-up dialog. If you have more than one domain listed, select the domain for which you desire to confirm ownership. Choose the method you wish to use to verify your domain: DNS Verification, Meta Tags or the HTML File Upload.

How do I add another domain to Facebook app?

Before you enter your domain, first click on Add Platform, select website, enter your site URL and mobile site url. Save the settings. Thereafter, you can enter the domain name in the App domains field.

How do I add multiple websites to Facebook?

With this simple trick you can list multiple sites on your Facebook profile page: Simply list the URLs for multiple sites in the Website textbox and separate them with a comma. They will display properly as separate links on your Profile page.


4 Answers

It is technically possible to use Facebook Connect on multiple domains, there are some limits (5 domains max).

So the key to doing this is adding all domains in the App Domain field under your app settings.

enter image description here

The PROBLEM, however, is that Facebook only lets you add domains that are derived from your Canvas URL or Site or Page tag URLs, so if you try to enter anything else you get an error that looks like this:

enter image description here

The SOLUTION is to create App on Facebook, Website, and Facebook Tab using the ADD PLATFORM button and then put in URLs that point to your other domains. Here is an example of what I mean:

enter image description here

If you use a unique domain for each field you can max out with 5 different domains. I have tested this technique with up to 3 domains, but i think it should work for all 5.

Note: Facebook admin features change from time to time, so all of this is subject to change

like image 183
Metablocks Corp Avatar answered Oct 20 '22 13:10

Metablocks Corp


As long as you listed all the desired App Domains in application settings you should be able to authenticate users on any of them.

"Website with Facebook Login" is really only intended to be used as link to your site/application.

Update 2 (July 2016):

App domains must match the domain of the Secure Canvas URL, Mobile Site URL, Unity Binary URL, Site URL or Secure Page Tab URL.

Update (December 2013):
At the time of writing original answer it was possible to list any domains in application settings but from that time the UI of Application Settings (as well as way of handling Application Domains) changed at least couple of times, at some point you could only list domains that derive from one of application's canvas pages.

As of December 2013 it is possible (again) to list domains that do not derive from application canvas URL.

Application Domains Settings

like image 25
Juicy Scripter Avatar answered Oct 20 '22 12:10

Juicy Scripter


Assuming your domains are being served by the same web server and you have access to that web server, you can use the manual login procedure: https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow to login from as many domains as you wish.

Assume your domains are site1.com,site2.com.... Instead of using the Facebook javascript API, you will simply place a plain old Log In with Facebook button on each site which will redirect the browser to the facebook login page as described in the above article. In the state variable you can specify a code which indicates which of your sites is requesting a login. In the redirect you will use a single service domain which you assign to your web server (e.g. fb.mywebserver.com) and which you specify as the verified redirect url in the facebook login settings page. All the sites will redirect to this same url, avoiding the problem of supporting multiple domains.

Once the user has logged in, the browser will redirect to fb.mywebserver.com and pass it the state, which tells you which site is requesting login and a code which you can use on the back end to retrieve the user's info using the Facebook graph apis. You store this info with a uid in your data store then using the info in state, you redirect to to the appropriate site including a parameter that indicates a Facebook login (e.g. site1.com?fbc={some uid}). The browser will obediently then call site1.com?fbc... Your web server will receive this request and detect the fbc parameter which tells it to associate the corresponding Facebook logged in user with this site. It can then retrieve the logged in users info using the uid and, for example, return a session cookie for this user along with the page. If you generate the page on the server you can, of course, also include a welcome "user" or alternatively, your client code can do an ajax call to retrieve that information.

From the user's standpoint they press the Login with Facebook button, are redirected to a Facebook login page where they login and then are redirected back to your site in a logged in state. Not quite as nice as having the login popup but likely acceptable.

A similar process can be used for google logins as well

like image 40
smjhunt Avatar answered Oct 20 '22 12:10

smjhunt


Best thing I've found to do in the development/production scenario is add a "Test App", then add a platform for your development web site - as you have to provide where the "page tab url" lives if you use that as a platform.

Facebook requires your "page url" to be live / accessible if you need to apply for status or permission review.

This got me around the "login in development" / "login in production" scenario.

like image 20
Subimage Avatar answered Oct 20 '22 12:10

Subimage