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



95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/sorcery/model/submodules/external.rb', line 95

def add_provider_to_user(provider, uid)
  authentications = sorcery_config.authentications_class.name.demodulize.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