Rails - Omniauth-facebook App_id required error
Asked Answered
B

1

5

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,

Bakelite answered 24/1, 2015 at 14:52 Comment(0)
H
11

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.

Houseline answered 24/1, 2015 at 16:39 Comment(1)
An amazing explanation :) Thanks very much. Will lean on the env variables right noe :)Bakelite

© 2022 - 2024 — McMap. All rights reserved.