Class: LeveretAuth::Strategies::LdapStrategy

Inherits:
BaseStrategy show all
Defined in:
lib/leveret_auth/strategies/ldap_strategy.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseStrategy

config, #initialize

Constructor Details

This class inherits a constructor from LeveretAuth::Strategies::BaseStrategy

Class Method Details

.clientObject



9
10
11
# File 'lib/leveret_auth/strategies/ldap_strategy.rb', line 9

def client
  @client ||= Ldap::Connection.new(config)
end

.configure(configuration) ⇒ Object



13
14
15
# File 'lib/leveret_auth/strategies/ldap_strategy.rb', line 13

def configure(configuration)
  @config = Ldap::Configuration.new(configuration)
end

Instance Method Details

#authenticate!Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/leveret_auth/strategies/ldap_strategy.rb', line 18

def authenticate!
  entrys = client.search(@email)
  raise Errors::InvalidCredential if entrys.nil?

  verified_entry = entrys.find { |entry| client.bind_as(entry.dn, @password) }
  raise Errors::InvalidCredential if verified_entry.nil?

  user_model.setup_user_from_third_party(uid: verified_entry.dn,
                                         provider: 'ldap',
                                         email: @email)
end