devise Add Model Concern omniauth_attributes_concern.rb


module OmniauthAttributesConcern
    extend ActiveSupport::Concern
    module ClassMethods
        Add Methods here 

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)}") 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

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' in remote_image_url is the DB column. You can use any other gem and pass params['info']['image'] to it.