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:
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.
Modify the code where you initialize the Facebook App ID and App Secret
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 == &amp;amp;amp;amp;quot;development&amp;amp;amp;amp;quot; || Rails.env == &amp;amp;amp;amp;quot;test&amp;amp;amp;amp;quot; config.omniauth :facebook, &amp;amp;amp;amp;quot;App_ID (Development Facebook App)&amp;amp;amp;amp;quot;, &amp;amp;amp;amp;quot;App_Secret (Development Facebook App)&amp;amp;amp;amp;quot; else config.omniauth :facebook, &amp;amp;amp;amp;quot;App_ID (Production Facebook App)&amp;amp;amp;amp;quot;, &amp;amp;amp;amp;quot;App_Secret (Production Facebook App)&amp;amp;amp;amp;quot; end
Troubleshooting
- If you get an error like “SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed”
Macs – http://martinottenwaelter.fr/2010/12/ruby19-and-the-ssl-error/
Windows – https://gist.github.com/867550