Module: Sorcery::Model::Submodules::External::InstanceMethods

Defined in:
lib/sorcery/model/submodules/external.rb

Instance Method Summary collapse

Instance Method Details

#add_provider_to_user(provider, uid) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/sorcery/model/submodules/external.rb', line 81

def add_provider_to_user(provider, uid)
  authentications = sorcery_config.authentications_class.name.underscore.pluralize
  # first check to see if user has a particular authentication already
  if sorcery_adapter.find_authentication_by_oauth_credentials(authentications, provider, uid).nil?
    user = send(authentications).build(sorcery_config.provider_uid_attribute_name => uid,
                                       sorcery_config.provider_attribute_name => provider)
    user.sorcery_adapter.save(validate: false)
  else
    user = false
  end

  user
end