Class: OmniAuth::Strategies::LDAP
- Inherits:
-
Object
- Object
- OmniAuth::Strategies::LDAP
- Includes:
- OmniAuth::Strategy
- Defined in:
- lib/omniauth/strategies/ldap.rb
Instance Method Summary collapse
- #auth_hash(entry) ⇒ Object
- #callback_phase ⇒ Object
- #entry_attr(entry, key) ⇒ Object
-
#initialize(app, name, host, port, base, options = {}) ⇒ LDAP
constructor
A new instance of LDAP.
- #request_phase ⇒ Object
Constructor Details
#initialize(app, name, host, port, base, options = {}) ⇒ LDAP
Returns a new instance of LDAP.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/omniauth/strategies/ldap.rb', line 9 def initialize(app, name, host, port, base, = {}) @options = @base = base @identifier_key = [:identifier_key] || "uid" @ldap = Net::LDAP.new(:host => host, :port => port) if [:username] && [:password] @ldap.auth [:username], [:password] end super(app, name) end |
Instance Method Details
#auth_hash(entry) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/omniauth/strategies/ldap.rb', line 44 def auth_hash(entry) OmniAuth::Utils.deep_merge(super(), { 'uid' => (entry.send @identifier_key)[0], 'strategy' => self.class.to_s, 'user_info' => { 'name' => entry_attr(entry, :name), 'displayName' => entry_attr(entry, :displayName), 'uid' => entry_attr(entry, :uid), 'email' => entry_attr(entry, :mail) || entry_attr(entry, :email) } }) end |
#callback_phase ⇒ Object
58 59 60 |
# File 'lib/omniauth/strategies/ldap.rb', line 58 def callback_phase @app.call(env) end |
#entry_attr(entry, key) ⇒ Object
62 63 64 |
# File 'lib/omniauth/strategies/ldap.rb', line 62 def entry_attr(entry, key) (entry.attribute_names.member?(key) && entry.send(key) && (entry.send key)[0]) || nil end |
#request_phase ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/omniauth/strategies/ldap.rb', line 23 def request_phase return fail!(:missing_information) unless (request[:identifier] && request[:password]) result = @ldap.bind_as(:base => @base, :filter => "(#{@identifier_key}=#{request[:identifier]})", :password => request[:password]) if result env['REQUEST_METHOD'] = 'GET' env['PATH_INFO'] = request.path + '/callback' request['auth'] = auth_hash(result.first) @app.call(env) else fail!(:invalid_credentials) end end |