0

I'm working on implementing omniauth into a Rails project. My problem is that the authentication providers - Twitter, Google, Facebook etc all require me to create an application with a url that limits authentication requests from anywhere other than the url. I need to be able to to test locally but also run code in production, but Facebook for example doesn't allow 2 domains and doesn't allow localhost anyhow.

So what are my options?

Undistraction
  • 42,754
  • 56
  • 195
  • 331

4 Answers4

3

Here's a blog post with my solution: http://make.bettermistak.es/2012/05/03/how-to-create-a-local-sandbox-facebook-app/

Here's the relevant bit: "Facebook verifies that all requests for your app are coming from the right domain–they don’t allow requests from localhost or 127.0.0.1–and this info can be updated in your apps settings under Hosting URL. Add “local.herokuapp.com” to your Hosting URLs and save this setting. Then edit your /etc/hosts file so that local content is under the domain local.herokuapp.com. This file is hidden, so from the command line enter sudo vi /etc/hosts. (Substitute your favorite editor for vi.) We need to use sudo, because this file is locked. Add the line “127.0.0.1 local.herokuapp.com” below “127.0.0.1 localhost” and save and quit your text editor."

Strand McCutchen
  • 3,157
  • 1
  • 16
  • 8
3

At work, we have multiple applications setup for the different environments. On local, add an entry in /etc/hosts (assuming you are on linux) eg: 127.0.0.1 mydomain.local.

On the facebook app setup for the local environment, add this as the url. Most things, except where facebook needs to scrape your site (Like buttons) work.

zsquare
  • 9,916
  • 6
  • 53
  • 87
1

As far as I know, you must sing up two apps for you app.(one for remote side, one for local side)

Fortunately, there is a way to reduce the complication(Assuming you are working on linux):

You can configure you .bash_profile (local machine and remote machine separately):

export YOURAPP_APP_ID="XXXXX"                                         
export YOURAPP_APP_SECRET="XXXXX"

And use ENV['YOURAPP_APP_ID'] and ENV['YOURAPP_APP_SECRET'] in your code. For example, you can code like this in rails:

config.omniauth :facebook, ENV['YOURAPP_APP_ID'], ENV['YOURAPP_APP_SECRET']

By this way, you can use the same code in both local and remote side. It will be much easier for maintaining.

If you are using Heroku to host your application, you can refer to this page to config the environment variables.

Brian
  • 30,156
  • 15
  • 86
  • 87
0

I have created two apps on Facebook one of which i run in sandbox mode for development purposes. Would that be an option for you?

Volker Pacher
  • 1,827
  • 18
  • 8
  • Thanks. Yes, that is a possibility. It still doesn't solve the problem that I can't use localhost for Facebook though. – Undistraction Jan 11 '12 at 12:37
  • if you have a dynamic ip you could use something like dyndns.com to assign a fqdn, that is what we are doing here and using for the development app. – Volker Pacher Jan 11 '12 at 12:43