Rails devise omniauth facebook
<p>I can't get devise omniauth-facebook to work. I've followed the devise guide to no avail. I think my problem is the model is not retrieving info.</p>

<p>Model</p>

<pre><code>class User &lt; ActiveRecord::Base
  has_attached_file :image, styles: {large: "1920x1080#", medium:              "800x500#", thumb: "100x100"}, :default_url =&gt;    "/images/:style/missing.png"
  validates_attachment_content_type :image, :content_type =&gt;    ["image/jpg", "image/jpeg", "image/png", "image/gif"]

  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable,
     :omniauthable, :omniauth_providers =&gt; [:facebook]
  def admin?
    admin
  end

  def self.from_omniauth(auth)
    where(provider: auth.provider, uid: auth.uid).first_or_create do     |user|
      user.email = auth.info.email
      user.password = Devise.friendly_token[0,20]
      user.name = auth.info.name   # assuming the user model has a     name
      user.image = auth.info.image # assuming the user model has an image
      puts request.env["omniauth.auth"]
    end
  end

  def self.new_with_session(params, session)
    super.tap do |user|
      if data = session["devise.facebook_data"] &amp;&amp;     session["devise.facebook_data"]["extra"]["raw_info"]
        user.email = data["email"] if user.email.blank?
      end
    end
  end
end
</code></pre>

<p>Routes.rb</p>

<pre><code>Rails.application.routes.draw do

  mount RailsAdmin::Engine =&gt; '/admin', as: 'rails_admin'

  devise_for :users do
    delete 'logout' =&gt; 'sessions#destroy', :as =&gt; :destroy_user_session,
    :controllers =&gt; { :omniauth_callbacks =&gt; "user/omniauth_callbacks" }
  end
</code></pre>

<p>Controller</p>

<pre><code>class User::OmniauthCallbacksController &lt;         Devise::OmniauthCallbacksController
  # You should configure your model like this:
  # devise :omniauthable, omniauth_providers: [:twitter]

  # You should also create an action method in this controller like this:
  # def twitter
  # end
  def facebook
    # You need to implement the method below in your model (e.g. app/models/user.rb)
    @user = User.from_omniauth(request.env["omniauth.auth"])
    if @user.persisted?
      sign_in_and_redirect @user, :event =&gt; :authentication #this will throw if @user is not activated
      set_flash_message(:notice, :success, :kind =&gt; "Facebook") if is_navigational_format?
    else
      session["devise.facebook_data"] = request.env["omniauth.auth"]
      redirect_to new_user_registration_url
    end
  end

  def self.new_with_session(params, session)
    if session["devise.user_attributes"]
      new(session[devise.user_attributes], without_protection: true) do |user|
        user.attributes = params
        user.valid?
      end
    else
      super
    end
</code></pre>

<p>After I click "Login with facebook", it directs to a facebook url, I input a password, press enter, get redirected to the same page with a long url. (<a href="http://localhost:3000/demographics?code=AQDK1z40APoLiWykomxDDUljBUNHotenM4lzj_bZMhH8iQ74J_Nu_EUnPqBqkbNAeWQEPZwQs7YghqkB4eD7AoQLkN_RuYIlmotMtrJc4UyGRSe3CJIHcxp6kcB9BuYHA_Ldz0NMJvvGzOuvC-uDpFn6TyrzvV5v9LvivORXVduSsCy7_r6PcW8jxAkWqZzKyASXf26h8h3f_kha2d0KX6Ygft8ozN1HT9Xr-1y7ZtIKgTXEGMrqK950kASv2oTE0tQ5CYt6mfEZsVyLpykYIApOls8NLhjOaOIJewzV9EnLdSq0FbrvtedhhDmy-hg6IkRAbRVgwEkfUFsi9DXoxKyX&amp;state=bdbf498f33f67ef57f3f54b846f870f21bb80c039c099f1a#_=_" rel="nofollow">http://localhost:3000/demographics?code=AQDK1z40APoLiWykomxDDUljBUNHotenM4lzj_bZMhH8iQ74J_Nu_EUnPqBqkbNAeWQEPZwQs7YghqkB4eD7AoQLkN_RuYIlmotMtrJc4UyGRSe3CJIHcxp6kcB9BuYHA_Ldz0NMJvvGzOuvC-uDpFn6TyrzvV5v9LvivORXVduSsCy7_r6PcW8jxAkWqZzKyASXf26h8h3f_kha2d0KX6Ygft8ozN1HT9Xr-1y7ZtIKgTXEGMrqK950kASv2oTE0tQ5CYt6mfEZsVyLpykYIApOls8NLhjOaOIJewzV9EnLdSq0FbrvtedhhDmy-hg6IkRAbRVgwEkfUFsi9DXoxKyX&amp;state=bdbf498f33f67ef57f3f54b846f870f21bb80c039c099f1a#<em>=</em></a>)</p>

<p>EDIT:</p>

<p>Now I am getting</p>

<pre><code>Could not authenticate you from Facebook because "Invalid credentials".
</code></pre>