Rails: Omniauth - "Requires app_id"

I follow this railscast tutorial to configure omniauth for facebook authentication in my rails project: http://railscasts.com/episodes/360-facebook-authentication?autoplay=true . I have 4 minutes and all I have done so far is omniauth-facebook gem bundle 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 the error The parameter app_id is required .

+6
source share
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 similar to this one (assuming a 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 make sure that they are loading into the environment.

Finally, in your omniauth.rb initializer omniauth.rb enter exactly:

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

More about the topic here , for example.

You can also use the dotenv gem to process environment variables.

+8
source

You can set the keys in the ENV variable, as dgilperez says, or delete 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 (e.g. github), use an ENV variable as it is more secure.

+2
source

Source: https://habr.com/ru/post/982716/


All Articles