oa-ldap 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.rdoc ADDED
File without changes
data/LICENSE.rdoc ADDED
File without changes
data/README.rdoc ADDED
@@ -0,0 +1,14 @@
1
+ * requires the ruby implementation gem 'net-ldap'
2
+
3
+
4
+ Gemfile
5
+ ---
6
+ gem "oa-ldap", :require => 'omniauth/ldap'
7
+
8
+
9
+ Rack middleware
10
+ ---
11
+ config.middleware.use OmniAuth::Builder do
12
+ provider :LDAP, :local-ldap, "localhost", 10389, "ou=system", :identifier_key => "uid", :username => "uid=admin,ou=system", :password => "secret"
13
+ end
14
+
@@ -0,0 +1,7 @@
1
+ require 'omniauth/core'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ autoload :LDAP, 'omniauth/strategies/ldap'
6
+ end
7
+ end
@@ -0,0 +1,68 @@
1
+ require 'net/ldap'
2
+ require 'omniauth/core'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class LDAP
7
+ include OmniAuth::Strategy
8
+
9
+ def initialize(app, name, host, port, base, options = {})
10
+ @options = options
11
+ @base = base
12
+ @identifier_key = options[:identifier_key] || "uid"
13
+
14
+ @ldap = Net::LDAP.new(:host => host, :port => port)
15
+ if options[:username] && options[:password]
16
+ @ldap.auth options[:username], options[:password]
17
+ end
18
+
19
+ super(app, name)
20
+ end
21
+
22
+
23
+ def request_phase
24
+ return fail!(:missing_information) unless (request[:identifier] && request[:password])
25
+
26
+
27
+ result = @ldap.bind_as(:base => @base,
28
+ :filter => "(#{@identifier_key}=#{request[:identifier]})",
29
+ :password => request[:password])
30
+
31
+
32
+ if result
33
+ env['REQUEST_METHOD'] = 'GET'
34
+ env['PATH_INFO'] = request.path + '/callback'
35
+ request['auth'] = auth_hash(result.first)
36
+ @app.call(env)
37
+ else
38
+ fail!(:invalid_credentials)
39
+ end
40
+
41
+ end
42
+
43
+
44
+ def auth_hash(entry)
45
+ OmniAuth::Utils.deep_merge(super(), {
46
+ 'uid' => (entry.send @identifier_key)[0],
47
+ 'strategy' => self.class.to_s,
48
+ 'user_info' => {
49
+ 'name' => entry_attr(entry, :name),
50
+ 'displayName' => entry_attr(entry, :displayName),
51
+ 'uid' => entry_attr(entry, :uid),
52
+ 'email' => entry_attr(entry, :mail) || entry_attr(entry, :email)
53
+ }
54
+ })
55
+ end
56
+
57
+
58
+ def callback_phase
59
+ @app.call(env)
60
+ end
61
+
62
+ def entry_attr(entry, key)
63
+ (entry.attribute_names.member?(key) && entry.send(key) && (entry.send key)[0]) || nil
64
+ end
65
+
66
+ end
67
+ end
68
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oa-ldap
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Pedro Teixeira
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-08-07 00:00:00 -03:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: oa-core
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ - 0
31
+ - 3
32
+ version: 0.0.3
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: net-ldap
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 0
45
+ - 1
46
+ - 1
47
+ version: 0.1.1
48
+ type: :runtime
49
+ version_requirements: *id002
50
+ description: LDAP strategies for OmniAuth.
51
+ email: pedro.t@gmail.com
52
+ executables: []
53
+
54
+ extensions: []
55
+
56
+ extra_rdoc_files: []
57
+
58
+ files:
59
+ - lib/omniauth/strategies/ldap.rb
60
+ - lib/omniauth/ldap.rb
61
+ - README.rdoc
62
+ - LICENSE.rdoc
63
+ - CHANGELOG.rdoc
64
+ has_rdoc: true
65
+ homepage: http://github.com/pedroteixeira/oa-ldap
66
+ licenses: []
67
+
68
+ post_install_message:
69
+ rdoc_options: []
70
+
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ requirements: []
90
+
91
+ rubyforge_project:
92
+ rubygems_version: 1.3.7
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: LDAP strategies for OmniAuth.
96
+ test_files: []
97
+