Following the Wiki entry @
https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview
seems to provide some conflicting information.
It recommends adding the following to the 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
As well as overriding the new_with_session method as follows:
def self.new_with_session(params, session)
super.tap do |user|
if data = session["devise.facebook_data"] &&
session["devise.facebook_data"]["extra"]["user_hash"]
user.email = data["email"]
end
end
end
However the new _with_session method doesn't seem to actually get
called when creating a new user via facebook since it just goes
straight to User.create!
I added code to new_with_session to grab some session data and attach
it to the new user but it only seems to work when creating a new user
through the form rather than through Facebook. What's the best
practice so Omniauth registration also calls new_with_session?