Rails - OmniAuth-Facebook throws NoSessionError

I am new to Rails and I am struggling with incorporating OmniAuth-Facebook into my existing rail. I followed the railscast tutorial (http://railscasts.com/episodes/360-facebook-authentication), but when I hit / auth / facebook I got a NoSessionError exception and it says that it should provide an OmniAuth session. I would post the code, but this is exactly the same as in the railscast tutorial.

He blew this line in the .rb strategy in OmniAuth: raise OmniAuth :: NoSessionError.new ("You must provide a session to use OmniAuth."), If only env ['rack.session']

Do I need to explicitly start a session?

+6
source share
1 answer

Make sure you set environment variables. The Railscast manual requires your App ID/API Key and App Secret be set as environment variables, so the omniauth initializer can connect

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

For this:

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

Two other routes for this is to create config.yml in your config / directory using

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

Add this to your config / application.rb

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

Then specify them in your initializer using AppConfig[:app_secret] and AppConfig[:app_id]

The last option is to simply copy the values ​​to the provider and remove the ENV

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

The second option is most preferred.

+1
source

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


All Articles