rubyruby-on-rails-5omniauthomniauth-facebook

Getting NIL response from Omniauth Facebook in Rails


I am trying to use Omniauth for login with Facebook in my Rails app, it seems to be working when i view the response in the console view, but I am not getting any information back in env['omniauth.auth'], when I try to inspect it returns NIL.

But in console, I can see the response as:

Object { accessToken="EAAHQ5CgynEoBAFfoTk5kSs7...WxZCw1fDHLQ4CBEspCgBAZD",  userID="1268814806542277",  expiresIn=7198,  more...} 

I use Rails 5.0.0.1 and Ruby 2.3.0p0

Gemfile

gem 'omniauth'
gem 'omniauth-facebook', '1.4.0'

omniauth.rb

OmniAuth.config.logger = Rails.logger

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :facebook, 'APP ID', 'APP SECRET', scope: 'email', display: 'popup', :info_fields => 'name,email', :include_granted_scopes => true
end

sessions_controller

class SessionsController < ApplicationController
  def create
    abort(env["omniauth.auth"].inspect)     // here I am getting the NIL response
    user = User.from_omniauth(env["omniauth.auth"])
    session[:user_id] = user.id
    return redirect_to new_user_session_path
  end

  def destroy
    session[:user_id] = nil
    return redirect_to root_url
  end 
end

Why might this be happening?


Solution

  • So finally I found the issue. The problem was with the devise.rb, I was using the following code in my devise.rb, I just removed those lines, and it started working.

    config.omniauth :facebook, app_id, app_secret, scope: 'email, public_profile'