Reputation: 217
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
.
Upvotes: 6
Views: 9718
Reputation: 10796
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.
Upvotes: 9
Reputation: 9108
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.
Upvotes: 3