Having trouble with Devise /OmniAuth

Hi All,

I am using the Devise 1.2 to integrate with OmniAuth (https://
OmniAuth: Overview · heartcombo/devise Wiki · GitHub). The
authorization/callback process works fine but I am not able to access
information from the user_info hash that is passed through the
request. I have tried several things within the Users controller but I
can’t seem to fill current_user.name/image/ etc. I am new to Rails
and have hit somewhat of a road block and I am just looking for some
direction. I have exhausted the options that I am familiar with…

----User Model—

def self.find_for_facebook_oauth(access_token, signed_in_resource=nil)
data = access_token[‘extra’][‘user_hash’]
if user = User.find_by_email(data[“email”])
user
else # Create an 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”]
user(:email => data[“email”],:name =>
data[“name”], :avatar_url => data[“image”])
end
end
end

In the self.new_with_sessions…I added the attributes to user
thinking that they would be created with the new session

Thanks,

Stephen

Hi Stephen,

I have recently finished a Rails 3 course, and the instructor
recommends a Devise + CanCan combo.

If you make a research you will see this option being used all around.

Take this one as an example:

http://www.tonyamoyal.com/2010/07/28/rails-authentication-with-devise-and-cancan-customizing-devise-controllers/

All the best.


MarcRic

http://www.traineronrails.com/
http://groups.google.com.br/group/riorubyrails

I am using Omniauth for the purpose of connecting the user to my app
via facebook/twitter…therefore the CanCan combo wont really be of
much use unless I assign privileges to certain users in my app. The
issue I am encountering is specific to the hash of user specific
information that facebook/twitter passes into my app via the
registration callback.

thanks for the suggestion.

Hi
My guess is that you need to add your new columns (name, avatar_url) to
your attr_accessible.
/Markus

With something as important as authentication, I just don’t see the need
to use devise. I prefer writing my own authentication solution. I’ve
used devise and it’s very detailed. But, like many authentication
solutions out there, it never covers everything I need.

My suggestion to you is to create your own.

Here’s an easy railscast that can help you with creating a very simple
solution, and one that you can eventually adapt to support omniauth.