Auth42 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d41e9b0fedb1aa27d04f01a5387d048ed81d6c8a
4
+ data.tar.gz: ba1dcce36c02a6673e8ccc1f4abbd517bd34b6a0
5
+ SHA512:
6
+ metadata.gz: 8d729ddd4dbacc1a73af4d93e82ffadd3f11ae5edebb87242c76340dd33448d90dbb2dd265a1c2c878d321bfa6e5d17fb52ce42b013a064d7b86759ee362f648
7
+ data.tar.gz: b9a2d3de814ef2b907d373935ad51a30b02175a844bda9dc717788b6b4ee80045e58b91b74b121f8357d1d6d0d6030b5aebaa1961a67da550ddc1f68442d9844
File without changes
@@ -0,0 +1,5 @@
1
+ if defined? Rails
2
+ require 'auth_42/railtie'
3
+ else
4
+ require 'auth_42/simple_auth'
5
+ end
@@ -0,0 +1,3 @@
1
+ require "auth_42/simple_auth"
2
+
3
+ ActionView::Base.send :include, Auth42
@@ -0,0 +1,77 @@
1
+ module Auth42
2
+ require 'net/ldap'
3
+
4
+ class SimpleAuth
5
+ S_URL = "ldap.42.fr"
6
+ S_PORT = 636
7
+ S_ENCRYPTION = {:method => :simple_tls}
8
+ S_BASE = "ou=2013,ou=people,dc=42,dc=fr"
9
+
10
+
11
+ # constructor method
12
+ def initialize
13
+ @handler = self.getHandler
14
+ end
15
+
16
+ def handler
17
+ @handler
18
+ end
19
+
20
+ def self.authenticate(user, password)
21
+ c = Net::LDAP.new(
22
+ :host => S_URL,
23
+ :port => S_PORT,
24
+ :base => S_BASE,
25
+ :encryption => S_ENCRYPTION,
26
+ :username => user,
27
+ :password => password
28
+ )
29
+ if c.bind
30
+ return true
31
+ else
32
+ return false
33
+ end
34
+ end
35
+
36
+ def search(query: "", filter: "", login: "", password: "")
37
+ if !login.empty? and !password.empty?
38
+ @handler = self.getAuthHandler(login, password)
39
+ end
40
+ if self.connect
41
+ q = {}
42
+ q[:filter] = filter unless filter.empty?
43
+ q[:attributes] = query unless query.empty?
44
+ results = @handler.search(q)
45
+ end
46
+ end
47
+
48
+ protected
49
+
50
+ def getHandler
51
+ c = Net::LDAP.new(
52
+ :host => S_URL,
53
+ :port => S_PORT,
54
+ :base => S_BASE,
55
+ :encryption => S_ENCRYPTION
56
+ )
57
+ c
58
+ end
59
+
60
+ def getAuthHandler(user, password)
61
+ c = Net::LDAP.new(
62
+ :host => S_URL,
63
+ :port => S_PORT,
64
+ :base => S_BASE,
65
+ :encryption => S_ENCRYPTION,
66
+ :username => user,
67
+ :password => password
68
+ )
69
+ c
70
+ end
71
+
72
+ def connect
73
+ @connected = @handler.bind
74
+ end
75
+ end
76
+
77
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Auth42
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - André Aubin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: net-ldap
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.5'
27
+ description: A simple ruby Gem to authenticate 42'school users
28
+ email: andre.aubin@lambdaweb.fr
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files:
32
+ - README.md
33
+ files:
34
+ - README.md
35
+ - lib/auth_42.rb
36
+ - lib/auth_42/railtie.rb
37
+ - lib/auth_42/simple_auth.rb
38
+ homepage: https://github.com/WeAreMuffin/Auth42-ruby
39
+ licenses:
40
+ - Apache2
41
+ metadata:
42
+ issue_tracker: https://github.com/WeAreMuffin/Auth42-ruby/issues
43
+ physical_requirements: Have an access on the 42 LDAP
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.2.2
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: Authenticate 42'school users
64
+ test_files: []