6
votes

I'm following this railscast tutorial to set up omniauth for facebook authentication on my rails project: http://railscasts.com/episodes/360-facebook-authentication?autoplay=true. I'm 4 minutes in and all I've done so far is bundle the gem omniauth-facebook and added,

omniauth.rb

OmniAuth.config.logger = Rails.logger

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :facebook, ENV['my id here...'], ENV['my secret code here...']

end

and then when I go to http://localhost:3000/auth/facebook I get an error saying The parameter app_id is required.

2
Did you actually add the ENV variables to your environment? Checked here are there? Restarted server? - dgilperez
Yes the ENV variables are there, took them out before posting here of course. And I just restated my server. But I'm unsure what you mean by "Checked here are there?" - roguerat
Sorry, typo. I mean if you checked the env variables are actually in your environment (ie you added them to ~/.bashrc but forgot to source ~/.bashrc would be a common mistake). You can stop your server, and, in the same console, type printenv | grep FACEBOOK_APP_ID or whatever your env variable is named - dgilperez

2 Answers

9
votes

Oh, now I see: you need to define environment variables to store your facebook_app_id and facebook_secret. You add them to your environment like this (assuming unix-like system):

Add this to the bottom of your ~/.bashrc file (or equivalent):

export FACEBOOK_APP_ID='your_id_here'
export FACEBOOK_SECRET='your_secret_here'

Then open a new terminal to be sure they get loaded in the environment.

At last, in your omniauth.rb initializer you type exactly:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_SECRET']
end

Read more about the topic here, for example.

You can also use dotenv gem to handle environment variables.

3
votes

You can set the keys on the ENV variable as dgilperez says, or remove the ENV and write it directly.

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :facebook, 'FACEBOOK_APP_ID', 'FACEBOOK_SECRET'
end

if you put the source code in a public repo (like github), use the ENV variable as it's more secure.