Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails - OmniAuth-Facebook throwing NoSessionError

I'm new to Rails, and I'm struggling with incorporating the OmniAuth-Facebook gem into my existing rails app. I've followed the railscast tutorial (http://railscasts.com/episodes/360-facebook-authentication) but when I hit /auth/facebook I get a NoSessionError exception, and it says I must provide a session to OmniAuth. I'd post code, but it's exactly like in the railscast tutorial.

It's blowing up on this line in strategy.rb in OmniAuth: raise OmniAuth::NoSessionError.new("You must provide a session to use OmniAuth.") unless env['rack.session']

Do I need to explicitly start a session?

like image 479
BrianTCU Avatar asked Oct 04 '12 03:10

BrianTCU


1 Answers

Make sure you're setting your environment variables. The Railscast tutorial requires that your App ID/API Key and App Secret keys are set as environment variables so that the omniauth initializer can connect

provider :facebook, ENV['APP_ID'], ENV['APP_SECRET']

To do this:

export APP_ID=(YOUR APP ID)
export APP_SECRET=(YOUR SECRET KEY)

Two other routes for doing this is to create a config.yml in your config/ directory with:

development:
  app_id:     'YOUR APP ID'
  app_secret: 'YOUR SECRET KEY'

Add this into your config/application.rb

AppConfig = YAML.load(ERB.new(File.read(File.expand_path('../config.yml', __FILE__))).result)[Rails.env]
AppConfig.symbolize_keys!

Then reference them in your initializer with AppConfig[:app_secret] and AppConfig[:app_id]

The last option is just to hardcode the values into the provider and remove the ENV

provider :facebook, 'YOUR APP ID', 'YOUR SECRET KEY'

The second option is the most preferable.

like image 116
BrianJakovich Avatar answered Nov 19 '22 09:11

BrianJakovich