Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7687783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:46:49+00:00 2026-05-31T19:46:49+00:00

I setup Facebook login with Devise and omniauth with these instructions https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview The Devise

  • 0

I setup Facebook login with Devise and omniauth with these instructions https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview

The Devise wiki gives some instructions for getting facebook info from the hash stored in this variable request.env['omniauth.auth'] See bottom for the hash.

For example, Devise wiki has these two methods for the User.rb model

def self.find_for_facebook_oauth(access_token, signed_in_resource=nil)
  data = access_token.extra.raw_info
  if user = User.where(:email => data.email).first
    user
  else # Create a user with a stub password. 
    User.create!(:email => data.email, :password => Devise.friendly_token[0,20]) 
  end
end

def self.new_with_session(params, session)
    super.tap do |user|
      if data = session["devise.facebook_data"] && session["devise.facebook_data"]["extra"]["raw_info"]
        user.email = data["email"]

      end
    end
  end

So, using the hash below, I added the following to those two methods to get the name and image

def self.find_for_facebook_oauth(access_token, signed_in_resource=nil)
  data = access_token.extra.raw_info
  if user = User.where(:email => data.email).first
    user
  else # Create a user with a stub password. 
    User.create!(:email => data.email, :password => Devise.friendly_token[0,20], :name => data.name, :image => access_token.info.image) #I added access_token.info.image based on first answer
  end
end

def self.new_with_session(params, session)
    super.tap do |user|
      if data = session["devise.facebook_data"] && session["devise.facebook_data"]["extra"]["raw_info"]
        user.email = data["email"]
        user.name = data["name"]
        user.image = access_token.info.image  #i changed this based on first answer below

      end
    end
  end

Then in my view, I added the following to show the user name and image

<p>Name:<%= user.name %></p>
 <p>Image: <%= image_tag user.image %>

However, only the name is showing. No image.

In my database, I have a name and an image column. The name from Facebook is being stored, but the image column says ‘nil’

Any ideas how I can get the image to work?

Hash stored in request.env['omniauth.auth'] https://github.com/mkdynamic/omniauth-facebook/blob/master/lib/omniauth/strategies/facebook.rb#L31-47

   info do
        prune!({
          'nickname' => raw_info['username'],
          'email' => raw_info['email'],
          'name' => raw_info['name'],
          'first_name' => raw_info['first_name'],
          'last_name' => raw_info['last_name'],
          'image' => "#{options[:secure_image_url] ? 'https' : 'http'}://graph.facebook.com/#{uid}/picture?type=square",
          'description' => raw_info['bio'],
          'urls' => {
            'Facebook' => raw_info['link'],
            'Website' => raw_info['website']
          },
          'location' => (raw_info['location'] || {})['name'],
          'verified' => raw_info['verified']
        })
      end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T19:46:50+00:00Added an answer on May 31, 2026 at 7:46 pm

    The image can be found at env["omniauth.auth"]["info"]["image"]. So in your case, access_token.info.image.

    If you want to take a good look at the hash of nested hashes returned and see for yourself where everything is, put this as the first line of your callback controller:

    render :text => "<pre>" + env["omniauth.auth"].to_yaml and return
    

    EDIT: Ok, so here’s what you need to do:

    def self.find_for_facebook_oauth(omniauth)
      if user = User.find_by_email(omniauth.info.email)
        if omniauth.info.image.present?
          user.update_attribute(:image, omniauth.info.image)
        end
        user
      else # Create a user with a stub password. 
        User.create!(:email => omniauth.info.email,
                     :name => omniauth.info.name,
                     :image => omniauth.info.image,
                     :password => Devise.friendly_token[0,20])
      end
    end
    

    As for the other method, if I’m not mistaken, it should look like this:

    def self.new_with_session(params, session)
      super.tap do |user|
        if omniauth = session["devise.facebook_data"]
          user.email = omniauth.info.email
          user.name = omniauth.info.name
          user.image = omniauth.info.image
        end
      end
    end
    

    But when is this method used? It’s used by Devise when something goes wrong when creating your user. Imagine that the authentication provider doesn’t give you an email (Twitter, for example, does this), what can you do? Well, you can redirect the user to your sign up page where he can complete the signup process. But if you redirect the user, you lose the data received by the oauth. The solution is to put this data into the session.

    So in your controller, you should have something like:

    if user.save
      sign_in_and_redirect user, :event => :authentication
    else
      session["devise.facebook_data"] = env["omniauth.auth"]
      redirect_to new_user_registration_url
    end
    

    Another problem, however, is that most of the times the data returned by the authentication provider is too big to fit in the session, so we have to pick exactly what we want to put in the session. Since you are only getting a name and an image, you can trim the extra info like so:

    session["devise.facebook_data"] = env["omniauth.auth"].except('extra')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I followed the devise official wiki to integrate devise with facebook through omniauth. I
I have successfully implemented login with Facebook using Devise and OmniAuth (built into Devise).
I have facebook login setup in my android app. When the user clicks login
I have some problem to setup application on facebook, ok what is exactly problems?
My Devise + Omniauth setup currently uses the following path to log a user
I'm following the tutorial here http://applicake.com/posts/54-integrating-facebook-connect-with-rails-applications to set up facebook connect. It almost worked,
Setup: I have a COM DLL that calls a method inside a managed C#
I'm trying to integrate facebook login on a site I'm working on, but so
I am simply trying to setup Facebook Connect to allow the choice on my
I am using the following code to rendered the facebook login button <div id=facebook-login>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.