Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: Omniauth - "The parameter app_id is required"

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.

like image 993
roguerat Avatar asked Feb 18 '15 23:02

roguerat


2 Answers

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.

like image 166
dgilperez Avatar answered Nov 18 '22 03:11

dgilperez


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.

like image 3
Alejandro Silva Avatar answered Nov 18 '22 02:11

Alejandro Silva