Running your application locally on your development machine is vital for quick feedback and easy testing. If you are are using Facebook’s OAuth as your authentication mechanism, it might get a bit more complicated to set up your application to run locally. Here’s a handy guide to getting Facebook OAuth to work even when running your app on your local development machine:
Step 1: Create a new App on the Facebook Developers website
- Visit the Facebook Developers website and log in
- Click on Apps in the main menu bar at the top and then click on “Create New App”
- For the App Name give it a descriptive name like “<App Name> – Development”
- Click on Settings > Basic in the menu on the left and then under the section “Select how your app integrates with Facebook”, you will see “Website with Facebook login”. Under this section fill in Site URL with “http://localhost:3000″ (or whatever port you use in your setup)
- Make sure to Save Changes
- At the very top you will see your App ID and App Secret. These will be important for the next step.
Step 2: Modify the code where you initialize the Facebook App ID and App Secret (Use Rails.env to switch out a different Facebook App ID And App Secret for the development environment)
Somewhere in your code (probably in an initializer), you’re setting the App ID and App Secret for your Facebook App. Change it to look like what’s given below. I’m using OmniAuth with Devise, but this technique will work with any other Facebook OAuth setup that you are using. Wherever you are setting the App ID and App Secret, change the code to switch out a different Facebook App ID And App Secret for the development machine.
if Rails.env == "development" || Rails.env == "test" config.omniauth :facebook, "App_ID (Development Facebook App)", "App_Secret (Development Facebook App)" else config.omniauth :facebook, "App_ID (Production Facebook App)", "App_Secret (Production Facebook App)" end
Step 3: If you get an error like “SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed”
For Macs - http://martinottenwaelter.fr/2010/12/ruby19-and-the-ssl-error/
For Windows - https://gist.github.com/867550