cas_client 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -0
- data/lib/cas_client/engine.rb +4 -2
- data/lib/cas_client/errors.rb +10 -1
- data/lib/cas_client/user_api.rb +17 -9
- data/lib/cas_client/version.rb +1 -1
- data/lib/generators/templates/cas_server.yml +22 -9
- data/lib/generators/templates/sessions_controller.rb +1 -1
- data/spec/spec_app/config/cas_server.yml +22 -9
- metadata +10 -10
data/Rakefile
CHANGED
data/lib/cas_client/engine.rb
CHANGED
@@ -14,9 +14,11 @@ module CASClient
|
|
14
14
|
::CAS_SERVER = YAML::load(File.open(Rails.root.to_s + '/config/cas_server.yml'))[Rails.env]
|
15
15
|
OmniAuth::Strategies.autoload :FacebookSignup, 'facebook_signup'
|
16
16
|
app.config.middleware.use OmniAuth::Builder do
|
17
|
-
provider :c_a_s, :cas_server => CAS_SERVER["
|
18
|
-
provider :facebook_signup, :cas_server => CAS_SERVER["
|
17
|
+
provider :c_a_s, :cas_server => CAS_SERVER["cas_domain"], :cas_service_validate_url => (CAS_SERVER["internal_cas_domain"] + '/serviceValidate')
|
18
|
+
provider :facebook_signup, :cas_server => CAS_SERVER["cas_domain"]
|
19
19
|
end
|
20
|
+
else
|
21
|
+
raise "A cas_server.yml configuration file is required. Please run 'rails g cas_client:install' to generate an example cas_server.yml file."
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
data/lib/cas_client/errors.rb
CHANGED
@@ -2,9 +2,18 @@ module CASClient
|
|
2
2
|
class UUIDNotFound < StandardError
|
3
3
|
end
|
4
4
|
|
5
|
-
class
|
5
|
+
class EmailAlreadyExists < StandardError
|
6
|
+
end
|
7
|
+
|
8
|
+
class EmailMissing < StandardError
|
6
9
|
end
|
7
10
|
|
8
11
|
class UserAlreadyExists < StandardError
|
9
12
|
end
|
13
|
+
|
14
|
+
class PasswordMissing < StandardError
|
15
|
+
end
|
16
|
+
|
17
|
+
class PasswordMismatch < StandardError
|
18
|
+
end
|
10
19
|
end
|
data/lib/cas_client/user_api.rb
CHANGED
@@ -21,12 +21,12 @@ module CASClient
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def cas_all
|
24
|
-
res = fetch("#{CAS_SERVER["
|
24
|
+
res = fetch("#{::CAS_SERVER["internal_cas_domain"]}/api/users")
|
25
25
|
Yajl::Parser.new(:symbolize_keys => true).parse(res.body)
|
26
26
|
end
|
27
27
|
|
28
28
|
def cas_fetch_user(uuid)
|
29
|
-
res = fetch("#{CAS_SERVER["
|
29
|
+
res = fetch("#{::CAS_SERVER["internal_cas_domain"]}/api/users/#{uuid}")
|
30
30
|
Yajl::Parser.new(:symbolize_keys => true).parse(res.body)
|
31
31
|
rescue CASClient::UUIDNotFound
|
32
32
|
end
|
@@ -37,13 +37,14 @@ module CASClient
|
|
37
37
|
|
38
38
|
def fetch(uri_string, limit = 10)
|
39
39
|
raise StandardError, 'HTTP redirect too deep' if limit == 0
|
40
|
+
uri_string = uri_string.gsub(/ /, '+')
|
40
41
|
url = URI.parse(uri_string)
|
41
42
|
handle_response(make_request(url, Net::HTTP::Get.new(url.path)), limit)
|
42
43
|
end
|
43
44
|
private :fetch
|
44
45
|
|
45
46
|
def make_request(url, req)
|
46
|
-
req.basic_auth CAS_SERVER["username"], CAS_SERVER["password"]
|
47
|
+
req.basic_auth ::CAS_SERVER["username"], ::CAS_SERVER["password"]
|
47
48
|
res = Net::HTTP.start(url.host, url.port) { |http| http.request(req) }
|
48
49
|
end
|
49
50
|
private :make_request
|
@@ -89,7 +90,7 @@ module CASClient
|
|
89
90
|
end
|
90
91
|
|
91
92
|
def cas_create
|
92
|
-
url = URI.parse("#{CAS_SERVER["
|
93
|
+
url = URI.parse("#{::CAS_SERVER["internal_cas_domain"]}/api/users")
|
93
94
|
res = handle_response(make_request(url, Net::HTTP::Post.new(url.path)))
|
94
95
|
Yajl::Parser.new(:symbolize_keys => true).parse(res.body)
|
95
96
|
end
|
@@ -100,30 +101,31 @@ module CASClient
|
|
100
101
|
else
|
101
102
|
_user_identifier = self.send(self.class.cas_map[:uuid])
|
102
103
|
end
|
103
|
-
url = URI.parse("#{CAS_SERVER["
|
104
|
+
url = URI.parse("#{::CAS_SERVER["internal_cas_domain"]}/api/users/#{_user_identifier}")
|
104
105
|
res = handle_response(make_request(url, Net::HTTP::Put.new(url.path)))
|
105
106
|
Yajl::Parser.new(:symbolize_keys => true).parse(res.body)
|
106
107
|
end
|
107
108
|
|
108
109
|
def cas_retrieve_attributes
|
109
|
-
res = fetch("#{CAS_SERVER["
|
110
|
+
res = fetch("#{::CAS_SERVER["internal_cas_domain"]}/api/users/#{self.send(self.class.cas_map[:uuid])}")
|
110
111
|
Yajl::Parser.new(:symbolize_keys => true).parse(res.body)
|
111
112
|
end
|
112
113
|
|
113
114
|
def cas_reset_password
|
114
|
-
res = fetch("#{CAS_SERVER["
|
115
|
+
res = fetch("#{::CAS_SERVER["internal_cas_domain"]}/api/users/#{self.send(self.class.cas_map[:uuid])}/reset_password")
|
115
116
|
res.body
|
116
117
|
end
|
117
118
|
|
118
119
|
def fetch(uri_string, limit = 10)
|
119
120
|
raise StandardError, 'HTTP redirect too deep' if limit == 0
|
121
|
+
uri_string = uri_string.gsub(/ /, '+')
|
120
122
|
url = URI.parse(uri_string)
|
121
123
|
handle_response(make_request(url, Net::HTTP::Get.new(url.path)), limit)
|
122
124
|
end
|
123
125
|
private :fetch
|
124
126
|
|
125
127
|
def make_request(url, req)
|
126
|
-
req.basic_auth CAS_SERVER["username"], CAS_SERVER["password"]
|
128
|
+
req.basic_auth ::CAS_SERVER["username"], ::CAS_SERVER["password"]
|
127
129
|
req.set_form_data(build_user_attributes_hash, ';') if [Net::HTTP::Post, Net::HTTP::Put].include?(req.class)
|
128
130
|
Net::HTTP.new(url.host, url.port).start { |http| http.request(req) }
|
129
131
|
end
|
@@ -140,9 +142,15 @@ module CASClient
|
|
140
142
|
when Net::HTTPForbidden
|
141
143
|
case Yajl::Parser.new(:symbolize_keys => true).parse(res.body)[:errors].first
|
142
144
|
when "Email is required to reset password"
|
143
|
-
raise CASClient::
|
145
|
+
raise CASClient::EmailMissing, "Email is required to reset password"
|
146
|
+
when "Email has already been taken"
|
147
|
+
raise CASClient::EmailAlreadyExists, "This unique email address has already been taken"
|
144
148
|
when "Uuid has already been taken"
|
145
149
|
raise CASClient::UserAlreadyExists, "This unique user ID has already been taken"
|
150
|
+
when "Password can't be blank"
|
151
|
+
raise CASClient::PasswordMissing, "Password is required"
|
152
|
+
when "Password doesn't match confirmation"
|
153
|
+
raise CASClient::PasswordMismatch, "Password and confirmation do not match"
|
146
154
|
else
|
147
155
|
puts res.body
|
148
156
|
res.error!
|
data/lib/cas_client/version.rb
CHANGED
@@ -1,14 +1,27 @@
|
|
1
1
|
development:
|
2
|
-
domain:
|
3
|
-
|
4
|
-
|
2
|
+
domain: http://localhost:3000
|
3
|
+
cas_domain: http://localhost:4000
|
4
|
+
internal_cas_domain: http://localhost:4000
|
5
|
+
username: test
|
6
|
+
password: password
|
5
7
|
|
6
8
|
test:
|
7
|
-
domain:
|
8
|
-
|
9
|
-
|
9
|
+
domain: http://localhost:3000
|
10
|
+
cas_domain: http://localhost:4000
|
11
|
+
internal_cas_domain: http://localhost:4000
|
12
|
+
username: test
|
13
|
+
password: password
|
14
|
+
|
15
|
+
qa:
|
16
|
+
domain: http://app.example.com
|
17
|
+
cas_domain: http://cas.example.com
|
18
|
+
internal_cas_domain: http://caslcl
|
19
|
+
username: test
|
20
|
+
password: password
|
10
21
|
|
11
22
|
production:
|
12
|
-
domain:
|
13
|
-
|
14
|
-
|
23
|
+
domain: http://app.example.com
|
24
|
+
cas_domain: http://cas.example.com
|
25
|
+
internal_cas_domain: http://caslcl
|
26
|
+
username: test
|
27
|
+
password: password
|
@@ -5,7 +5,7 @@ class SessionsController < CASClient::SessionsController
|
|
5
5
|
|
6
6
|
def create
|
7
7
|
# do whatever you need here to persist the users session within your app
|
8
|
-
# session[:uuid] = request.env['
|
8
|
+
# session[:uuid] = request.env['omniauth.auth']['uid']
|
9
9
|
# redirect_to '/'
|
10
10
|
end
|
11
11
|
|
@@ -1,14 +1,27 @@
|
|
1
1
|
development:
|
2
|
-
domain:
|
3
|
-
|
4
|
-
|
2
|
+
domain: http://localhost:3000
|
3
|
+
cas_domain: http://localhost:4000
|
4
|
+
internal_cas_domain: http://localhost:4000
|
5
|
+
username: test
|
6
|
+
password: password
|
5
7
|
|
6
8
|
test:
|
7
|
-
domain:
|
8
|
-
|
9
|
-
|
9
|
+
domain: http://localhost:3000
|
10
|
+
cas_domain: http://localhost:4000
|
11
|
+
internal_cas_domain: http://localhost:4000
|
12
|
+
username: test
|
13
|
+
password: password
|
14
|
+
|
15
|
+
qa:
|
16
|
+
domain: http://app.example.com
|
17
|
+
cas_domain: http://cas.example.com
|
18
|
+
internal_cas_domain: http://caslcl
|
19
|
+
username: test
|
20
|
+
password: password
|
10
21
|
|
11
22
|
production:
|
12
|
-
domain:
|
13
|
-
|
14
|
-
|
23
|
+
domain: http://app.example.com
|
24
|
+
cas_domain: http://cas.example.com
|
25
|
+
internal_cas_domain: http://caslcl
|
26
|
+
username: test
|
27
|
+
password: password
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cas_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ryan Moran
|
@@ -15,12 +15,10 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-04-18 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
name: oa-enterprise
|
23
|
-
prerelease: false
|
24
22
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
23
|
none: false
|
26
24
|
requirements:
|
@@ -32,11 +30,11 @@ dependencies:
|
|
32
30
|
- 1
|
33
31
|
- 6
|
34
32
|
version: 0.1.6
|
35
|
-
type: :runtime
|
36
33
|
version_requirements: *id001
|
37
|
-
|
38
|
-
name: yajl-ruby
|
34
|
+
name: oa-enterprise
|
39
35
|
prerelease: false
|
36
|
+
type: :runtime
|
37
|
+
- !ruby/object:Gem::Dependency
|
40
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
39
|
none: false
|
42
40
|
requirements:
|
@@ -46,8 +44,10 @@ dependencies:
|
|
46
44
|
segments:
|
47
45
|
- 0
|
48
46
|
version: "0"
|
49
|
-
type: :runtime
|
50
47
|
version_requirements: *id002
|
48
|
+
name: yajl-ruby
|
49
|
+
prerelease: false
|
50
|
+
type: :runtime
|
51
51
|
description: Helpers, controllers and middleware to implement a CAS client app
|
52
52
|
email:
|
53
53
|
- ryan.moran@revolutionprep.com
|