Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails - Omniauth-facebook App_id required error

I am interested in learning the omniauth authentication with rails so I checked different guides in which also contains Railscast #360.

When I create my own app with developers.facebook.com, it creates an App_id and secret for me. I set the application online and created a basic rails app that just uses the steps in the Ryan Bates guide.

This is my omniauth.rb file which generates the error that I am recieving,

 OmniAuth.config.logger = Rails.logger

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :facebook, ENV['875829959136178'], ENV['<app_secret>']
end

I have tried to use

provider :facebook, ENV['FACEBOOK_875829959136178'], ENV['FACEBOOK_<app_secret>']

also.

When I call http://localhost:3000/auth/facebook, I am recieving an error that indicates that "the parameter app_id is required".

How I can pass this error,

like image 317
Mustafa Yilmaz Avatar asked Jan 24 '15 14:01

Mustafa Yilmaz


1 Answers

It seems you misunderstand what ENV is. ENV[xxx] is a ruby method which retrieves the value for environment variable xxx. So ENV['875829959136178'] in your code snippet tries to retrieve the value for environment variable 875829959136178. It is very likely that you have not set your app_id to the environment variable 875829959136178, and thus ENV['875829959136178'] returns nil. provider is a method which takes the app_id and app_secret, but since you are giving nil as app_id, it is claiming that the app_id is not given even though it is required.

Let's say your app_id is 875829959136178 and your app_secret is APP_SECRET. The easiest way to make your app work is to give them as String.

provider :facebook, "875829959136178", "APP_SECRET"

You should note, though, that putting your app id and secret in source code as plain text is not desirable from security perspective. You should lean how to set environment variables by reading articles like this, or use gems like dotenv.

like image 91
tyamagu2 Avatar answered Nov 14 '22 18:11

tyamagu2