module OmniauthAttributesConcern
extend ActiveSupport::Concern
module ClassMethods
Add Methods here
end
end
In this concern we can create methods for each social media to fetch and store attributes.
def twitter params
(params['info']['email'] = "dummy#{SecureRandom.hex(10)}@dummy.com") if params['info']['email'].blank?
attributes = {
email: params['info']['email'],
first_name: params['info']['name'].split(' ').first,
last_name: params['info']['name'].split(' ').last,
username: params['info']['nickname'],
password: Devise.friendly_token
}
create(attributes)
end
Note: Twitter only returns an email address if the user has confirmed his/her email at Twitter; otherwise the
nil
value is returned.
We can add other social media accounts the same way we have added Twitter above.
The profile image from the social media account can also be fetched, and will be passed as
remote_image_url: params['info']['image']
Note: the above example is meant for the CarrierWave gem, and
'image'
inremote_image_url
is the DB column. You can use any other gem and passparams['info']['image']
to it.