Facebook login - how to develop on both localhost and in production?

14,718

Solution 1

Update: As of 2018 the path to this setting is now Products > Facebook Login > Settings > Client OAuth Settings the rest of this answer is still valid.


There is a better way. You just need to add valid callback URL's for your localhost to Settings > Advanced > OAuth Settings.

enter image description here

This method allows you still have your production website URL while allowing oauth from dev, staging, production, etc.

Solution 2

After I have worked with this for ~6 months, I have found a solution which works really well, based on the other two answers.

In Facebook I add two apps:

  • Production app
  • Dev app

Then, in my web.config app settings I have:

<!--Prod-->
<add key="_FacebookApiId" value="id"/>
<add key="_FacebookApiSecretId" value="secret_id"/>
<!--Dev-->
<add key="FacebookApiId" value="dev_id"/>
<add key="FacebookApiSecretId" value="dev_secret_id"/>

Which of course is read through a helper-class.

Then it works seamlessly on both production and localhost, and both myself and my team is happy.

Solution 3

I have the same problem.

The only solutions I have found are:

Solution 4

Facebook only allows localhost OAuth redirects when your app is in development mode. This means you can't run your application in production and perform local development tests.

Instead, you need to create a test variant of your app. Head to https://developers.facebook.com and view the dashboard for your production application. Click the drop-down menu at the top-left and choose Create Test App.

This populates a test application with almost the same settings as your production app. However, it gives you a new app ID and app secret, so you'll need to toggle these settings when running in development mode (as other answers suggest).

Here's some further info on test apps: https://developers.facebook.com/docs/apps/test-apps/

Share:
14,718
Lars Holdgaard
Author by

Lars Holdgaard

An entrepreneur since I was 18. Been building a lot of stuff: some successful, some not so successful Currently building the best debt collection company in the world at Likvido. In my free time (when not tinkering with code), I'm very much into crypto, traveling and being digital-nomad when it suits my lifestyle... And I blog at LarsHoldgaard.com!

Updated on June 03, 2022

Comments

  • Lars Holdgaard
    Lars Holdgaard almost 2 years

    I am developing a website which uses the Facebook login. Now, I want to be able to get this to work both in my production environment, as well as in my development environment.

    On Facebook, I can give ONE site url, which Facebook can redirect to. This worked great during my development phase, but now I want it both to work in production, but also while developing my solution.

    I guess one way would be to run my application on the local IIS with my domain-navn and change my hosts file, but that can't seriously be the most easy solution!?

    - What is the easiest way to get it to work in both environments?