oa-pubcookie 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/oa-pubcookie.rb +1 -0
- data/lib/omniauth/pubcookie.rb +13 -0
- data/lib/omniauth/pubcookie/cmu_ldap.rb +32 -0
- data/lib/omniauth/pubcookie/version.rb +5 -0
- data/lib/omniauth/strategies/cmu.rb +38 -0
- data/lib/omniauth/strategies/pubcookie.rb +50 -0
- metadata +110 -0
data/lib/oa-pubcookie.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'omniauth/pubcookie'
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'omniauth/core'
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module Pubcookie
|
5
|
+
autoload :VERSION, 'omniauth/pubcookie/version'
|
6
|
+
autoload :CMULdap, 'omniauth/pubcookie/cmu_ldap'
|
7
|
+
end
|
8
|
+
|
9
|
+
module Strategies
|
10
|
+
autoload :CMU, 'omniauth/strategies/cmu'
|
11
|
+
autoload :Pubcookie, 'omniauth/strategies/pubcookie'
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'net/ldap'
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module Pubcookie
|
5
|
+
module CMULdap
|
6
|
+
# Thanks to Marshall Roch for the original jump start for this code.
|
7
|
+
|
8
|
+
def lookup_andrew_id username
|
9
|
+
ldap = Net::LDAP.new :host => 'ldap.andrew.cmu.edu', :port => 389
|
10
|
+
|
11
|
+
filter = Net::LDAP::Filter.eq('cmuAndrewID', username)
|
12
|
+
attrs = ['givenName', 'sn', 'nickname', 'eduPersonSchoolCollegeName',
|
13
|
+
'cmuStudentClass', 'mail', 'cmuPreferredMail',
|
14
|
+
'cmuPersonPrincipalName']
|
15
|
+
|
16
|
+
ldap.search(:base => 'ou=Person,dc=cmu,dc=edu',
|
17
|
+
:filter => filter, :return_result => true) do |entry|
|
18
|
+
results = {}
|
19
|
+
|
20
|
+
entry.each do |attribute, values|
|
21
|
+
results[attribute] = values.first
|
22
|
+
end
|
23
|
+
|
24
|
+
return results
|
25
|
+
end
|
26
|
+
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'omniauth/strategies/pubcookie'
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module Strategies
|
5
|
+
class CMU < Pubcookie
|
6
|
+
|
7
|
+
include OmniAuth::Pubcookie::CMULdap
|
8
|
+
|
9
|
+
def pubcookie_options= options
|
10
|
+
options[:login_server] ||= 'webiso.andrew.cmu.edu'
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
def auth_hash username
|
15
|
+
andrew_id = username.match(/^(.*)@/)[1]
|
16
|
+
|
17
|
+
attrs = lookup_andrew_id(andrew_id)
|
18
|
+
|
19
|
+
OmniAuth::Utils.deep_merge(super, {
|
20
|
+
'uid' => andrew_id,
|
21
|
+
'provider' => 'cmu',
|
22
|
+
'user_info' => {
|
23
|
+
'name' => attrs[:cn],
|
24
|
+
'email' => attrs[:mail],
|
25
|
+
'nickname' => attrs[:nickname],
|
26
|
+
'first_name' => attrs[:givenname],
|
27
|
+
'last_name' => attrs[:sn],
|
28
|
+
'class' => attrs[:cmustudentclass],
|
29
|
+
'department' => attrs[:cmudepartment],
|
30
|
+
'location' => attrs[:cmucampus]
|
31
|
+
},
|
32
|
+
'extra' => {'user_hash' => attrs}
|
33
|
+
})
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'omniauth/strategy'
|
2
|
+
require 'rack/pubcookie'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
class Pubcookie
|
7
|
+
|
8
|
+
include OmniAuth::Strategy
|
9
|
+
include Rack::Pubcookie::Auth
|
10
|
+
|
11
|
+
def initialize app, options, &block
|
12
|
+
self.pubcookie_options = options
|
13
|
+
super app, :pubcookie, &block
|
14
|
+
end
|
15
|
+
|
16
|
+
def request_phase
|
17
|
+
Rack::Response.new(login_page_html).finish
|
18
|
+
end
|
19
|
+
|
20
|
+
def callback_phase
|
21
|
+
username = extract_username request
|
22
|
+
request.env['REMOTE_USER'] = username # Part of the pubcookie spec
|
23
|
+
|
24
|
+
if username
|
25
|
+
request.env['omniauth.auth'] = auth_hash(username)
|
26
|
+
request.env['REQUEST_METHOD'] = 'GET'
|
27
|
+
|
28
|
+
status, headers, body = call_app!
|
29
|
+
|
30
|
+
# Set the actual cookie for pubcookie, as per its spec
|
31
|
+
response = Rack::Response.new body, status, headers
|
32
|
+
set_pubcookie! request, response
|
33
|
+
|
34
|
+
response.finish
|
35
|
+
else
|
36
|
+
fail! :login_failed
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def auth_hash username
|
41
|
+
OmniAuth::Utils.deep_merge(super(), {
|
42
|
+
'uid' => username,
|
43
|
+
'provider' => 'pubcookie',
|
44
|
+
'user_info' => {'name' => username}
|
45
|
+
})
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: oa-pubcookie
|
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
|
+
- Alex Crichton
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-01-19 00:00:00 -05:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rack-pubcookie
|
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: oa-core
|
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
|
+
version: "0"
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: net-ldap
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
type: :runtime
|
60
|
+
version_requirements: *id003
|
61
|
+
description: Omniauth strategy using pubcookie with special additions for CMU students where information is fetched via LDAP
|
62
|
+
email:
|
63
|
+
- alex@crichton.co
|
64
|
+
executables: []
|
65
|
+
|
66
|
+
extensions: []
|
67
|
+
|
68
|
+
extra_rdoc_files: []
|
69
|
+
|
70
|
+
files:
|
71
|
+
- lib/oa-pubcookie.rb
|
72
|
+
- lib/omniauth/pubcookie.rb
|
73
|
+
- lib/omniauth/pubcookie/cmu_ldap.rb
|
74
|
+
- lib/omniauth/pubcookie/version.rb
|
75
|
+
- lib/omniauth/strategies/cmu.rb
|
76
|
+
- lib/omniauth/strategies/pubcookie.rb
|
77
|
+
has_rdoc: true
|
78
|
+
homepage: https://github.com/alexcrichton/oa-pubcookie
|
79
|
+
licenses: []
|
80
|
+
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
version: "0"
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
segments:
|
100
|
+
- 0
|
101
|
+
version: "0"
|
102
|
+
requirements: []
|
103
|
+
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 1.3.7
|
106
|
+
signing_key:
|
107
|
+
specification_version: 3
|
108
|
+
summary: Omniauth strategy using pubcookie
|
109
|
+
test_files: []
|
110
|
+
|