ruby-openid 1.0.2 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ruby-openid might be problematic. Click here for more details.

Files changed (54) hide show
  1. data/examples/cacert.pem +7815 -0
  2. data/examples/consumer.rb +2 -2
  3. data/examples/consumerd.rb +290 -0
  4. data/examples/openid-store/associations/http-localhost_3A3000_2Fserver-LQl7HUNueJIJcpPoAGiHEHNdJMc +6 -0
  5. data/examples/openid-store/associations/http-www.myopenid.com_2Fserver-ZFp96P4qV1FjqgGt2rtZBvRJWic +6 -0
  6. data/examples/openid-store/auth_key +1 -0
  7. data/examples/openid-store/nonces/PNiw86rQ +0 -0
  8. data/examples/openid-store/nonces/hdZo7WC9 +0 -0
  9. data/examples/openid-store/nonces/uHhMdi1i +0 -0
  10. data/examples/rails_openid_login_generator/templates/controller.rb +1 -1
  11. data/examples/rails_server/app/controllers/login_controller.rb~ +35 -0
  12. data/examples/rails_server/app/controllers/server_controller.rb~ +190 -0
  13. data/examples/rails_server/db/openid-store/associations/http-localhost_2F_7Cnormal-YU.tkND1J4fEZhnuAoT5Zc0yCA0 +6 -0
  14. data/examples/rails_server/db/openid-store/associations/http-localhost_2F_7Cnormal-jRS20gc5OzJ5pkpjy9BjqvTj3B0 +6 -0
  15. data/examples/rails_server/log/development.log +6459 -0
  16. data/examples/rails_server/log/production.log +0 -0
  17. data/examples/rails_server/log/server.log +0 -0
  18. data/examples/rails_server/log/test.log +0 -0
  19. data/examples/rails_server/tmp/sessions/ruby_sess.1b2e9635e0f69c0d +0 -0
  20. data/examples/rails_server/tmp/sessions/ruby_sess.1b3584d2b3784c97 +0 -0
  21. data/examples/rails_server/tmp/sessions/ruby_sess.20ed70e0e63d7e31 +0 -0
  22. data/examples/rails_server/tmp/sessions/ruby_sess.30cf5b98539677d5 +0 -0
  23. data/examples/rails_server/tmp/sessions/ruby_sess.3910508c0c857695 +0 -0
  24. data/examples/rails_server/tmp/sessions/ruby_sess.472170ef38098672 +0 -0
  25. data/examples/rails_server/tmp/sessions/ruby_sess.5406e21ba5b1c7bb +0 -0
  26. data/examples/rails_server/tmp/sessions/ruby_sess.5d2bd2b7086f12d5 +0 -0
  27. data/examples/rails_server/tmp/sessions/ruby_sess.968757c6d12af322 +0 -0
  28. data/examples/rails_server/tmp/sessions/ruby_sess.a87a5045744b3abf +0 -0
  29. data/examples/rails_server/tmp/sessions/ruby_sess.ca9f0a416be0be57 +0 -0
  30. data/examples/rails_server/tmp/sessions/ruby_sess.cd269e6040645b5b +0 -0
  31. data/examples/rails_server/tmp/sessions/ruby_sess.cf2acf62b93dbc88 +0 -0
  32. data/examples/rails_server/tmp/sessions/ruby_sess.d2ef8fe29591ef9b +0 -0
  33. data/examples/rails_server/tmp/sessions/ruby_sess.e23240e097e2c83d +0 -0
  34. data/examples/rails_server/tmp/sessions/ruby_sess.fb154d2f7c286aba +0 -0
  35. data/lib/openid/consumer.rb +40 -71
  36. data/lib/openid/discovery.rb +34 -1
  37. data/lib/openid/discovery.rb~ +122 -0
  38. data/lib/openid/fetchers.rb +41 -0
  39. data/lib/openid/server.rb +1 -1
  40. data/lib/openid/service.rb +9 -2
  41. data/lib/openid/stores.rb~ +178 -0
  42. data/lib/openid/trustroot.rb +23 -10
  43. data/lib/openid/urinorm.rb +72 -0
  44. data/lib/openid/util.rb +3 -3
  45. data/test/consumer.rb +0 -8
  46. data/test/data/urinorm.txt +79 -0
  47. data/test/runtests.rb +1 -0
  48. data/test/service.rb +18 -1
  49. data/test/teststore.rb~ +47 -0
  50. data/test/trustroot.rb +5 -1
  51. data/test/urinorm.rb +32 -0
  52. metadata +93 -41
  53. data/examples/rails_openid_login_generator/templates/controller.rb~ +0 -111
  54. data/test/runtests.rb~ +0 -21
data/test/runtests.rb CHANGED
@@ -19,3 +19,4 @@ require "assoc"
19
19
  require "server2"
20
20
  require "consumer"
21
21
  require "service"
22
+ require "urinorm"
data/test/service.rb CHANGED
@@ -7,6 +7,10 @@ class FakeYadis
7
7
  return ''
8
8
  end
9
9
 
10
+ def xrds_uri
11
+ ''
12
+ end
13
+
10
14
  end
11
15
 
12
16
  class OpenIDServiceEndpointTestCase < Test::Unit::TestCase
@@ -19,11 +23,24 @@ class OpenIDServiceEndpointTestCase < Test::Unit::TestCase
19
23
 
20
24
  service = xrds.services[0]
21
25
  service.yadis = FakeYadis.new
22
-
26
+
23
27
  openid_service = OpenID::OpenIDServiceEndpoint.from_endpoint(service)
24
28
  assert_not_nil(openid_service)
25
29
  assert_equal(openid_service.server_url, 'http://www.myopenid.com/server')
26
30
  end
31
+ File.open('data/brianellin.mylid.xrds') do |f|
32
+ xrds = XRDS.new(f.read)
33
+ assert_not_nil(xrds)
34
+ assert_equal(xrds.services.length, 9)
35
+
36
+ service = xrds.services[8]
37
+ assert_not_nil(service)
38
+ service.yadis = FakeYadis.new
39
+
40
+ openid_service = OpenID::OpenIDServiceEndpoint.from_endpoint(service)
41
+ assert_not_nil(openid_service)
42
+ assert_equal(openid_service.server_url, 'http://mylid.net/brianellin')
43
+ end
27
44
  end
28
45
 
29
46
  end
@@ -0,0 +1,47 @@
1
+ require 'test/unit'
2
+ require 'fileutils'
3
+ require 'pathname'
4
+ require 'tmpdir'
5
+
6
+ require 'openid/filestore'
7
+ require 'storetestcase'
8
+
9
+ class FileStoreTestCase < Test::Unit::TestCase
10
+ include StoreTestCase
11
+
12
+ @@dir = Pathname.new(Dir.tmpdir).join('filstoretest')
13
+
14
+ def setup
15
+ FileUtils.rm_rf(@@dir)
16
+ @store = OpenID::FilesystemStore.new(@@dir)
17
+ end
18
+
19
+ def teardown
20
+ FileUtils.rm_rf(@@dir)
21
+ end
22
+ end
23
+
24
+ class DumbStoreTestCase < Test::Unit::TestCase
25
+ include StoreTestCase
26
+
27
+ def setup
28
+ @store = OpenID::DumbStore.new('unit-test')
29
+ end
30
+
31
+ def test_nonce
32
+ assert_equal(true, @store.use_none('anything'))
33
+ end
34
+
35
+ end
36
+
37
+ class MemoryStoreTestCase < Test::Unit::TestCase
38
+ include StoreTestCase
39
+
40
+ @@dir = Pathname.new(Dir.tmpdir).join('filstoretest')
41
+
42
+ def setup
43
+ @store = OpenID::MemoryStore.new
44
+ end
45
+
46
+ end
47
+
data/test/trustroot.rb CHANGED
@@ -53,7 +53,7 @@ class TrustRootTestCase < Test::Unit::TestCase
53
53
  def assert_sane(s, expected)
54
54
  tr = OpenID::TrustRoot.parse(s)
55
55
  assert_not_nil(tr)
56
- assert_equal(tr.sane?, expected)
56
+ assert_equal(tr.sane?, expected, s)
57
57
  end
58
58
 
59
59
  assert_sane('http://*/', false)
@@ -66,6 +66,8 @@ class TrustRootTestCase < Test::Unit::TestCase
66
66
  assert_sane('http://localhost:8082/?action=openid', true)
67
67
  assert_sane('http://*.foo.notatld', false)
68
68
  assert_sane('http://*.museum/', false)
69
+ assert_sane('http://kink.fm/', true)
70
+ assert_sane('http://beta.lingu.no/', true)
69
71
  end
70
72
 
71
73
  def test_validate
@@ -77,6 +79,8 @@ class TrustRootTestCase < Test::Unit::TestCase
77
79
  assert_equal(tr.validate_url(url), expected)
78
80
  end
79
81
 
82
+ assert_valid('http://*.foo.com', 'http://foo.com', true)
83
+ assert_valid('http://*.foo.com/', 'http://foo.com/', true)
80
84
  assert_valid('http://*.foo.com', 'http://b.foo.com', true)
81
85
  assert_valid('http://*.foo.com', 'http://b.foo.com/', true)
82
86
  assert_valid('http://*.foo.com', 'http://b.foo.com/', true)
data/test/urinorm.rb ADDED
@@ -0,0 +1,32 @@
1
+ require 'test/unit'
2
+ require "openid/urinorm"
3
+
4
+ class URINormTestCase < Test::Unit::TestCase
5
+
6
+ def test_normalize
7
+ lines = File.readlines('data/urinorm.txt')
8
+
9
+ while lines.length > 0
10
+
11
+ case_name = lines.shift.strip
12
+ actual = lines.shift.strip
13
+ expected = lines.shift.strip
14
+ _newline = lines.shift
15
+
16
+ if expected == 'fail'
17
+ begin
18
+ OpenID::Util::urinorm(actual)
19
+ rescue URI::InvalidURIError
20
+ assert true
21
+ else
22
+ raise 'Should have gotten URI error'
23
+ end
24
+ else
25
+ normalized = OpenID::Util.urinorm(actual)
26
+ assert_equal(expected, normalized, case_name)
27
+ end
28
+ end
29
+ end
30
+
31
+ end
32
+
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: ruby-openid
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.2
7
- date: 2006-06-12 00:00:00 -07:00
6
+ version: 1.1.1
7
+ date: 2006-08-20 00:00:00 -07:00
8
8
  summary: A library for consuming and serving OpenID identities.
9
9
  require_paths:
10
10
  - lib
@@ -28,14 +28,17 @@ cert_chain:
28
28
  authors:
29
29
  - Brian Ellin (JanRain, Inc)
30
30
  files:
31
- - examples/consumer.rb
32
31
  - examples/rails_server
32
+ - examples/consumer.rb
33
33
  - examples/README
34
+ - examples/cacert.pem
34
35
  - examples/rails_openid_login_generator
35
36
  - examples/rails_active_record_store
37
+ - examples/openid-store
38
+ - examples/consumerd.rb
36
39
  - examples/rails_server/app
37
- - examples/rails_server/components
38
40
  - examples/rails_server/config
41
+ - examples/rails_server/components
39
42
  - examples/rails_server/db
40
43
  - examples/rails_server/doc
41
44
  - examples/rails_server/lib
@@ -46,16 +49,19 @@ files:
46
49
  - examples/rails_server/vendor
47
50
  - examples/rails_server/Rakefile
48
51
  - examples/rails_server/README
52
+ - examples/rails_server/tmp
49
53
  - examples/rails_server/app/controllers
50
54
  - examples/rails_server/app/helpers
51
55
  - examples/rails_server/app/models
52
56
  - examples/rails_server/app/views
53
- - examples/rails_server/app/controllers/server_controller.rb
54
- - examples/rails_server/app/controllers/login_controller.rb
55
57
  - examples/rails_server/app/controllers/application.rb
56
- - examples/rails_server/app/helpers/server_helper.rb
57
- - examples/rails_server/app/helpers/login_helper.rb
58
+ - examples/rails_server/app/controllers/login_controller.rb
59
+ - examples/rails_server/app/controllers/server_controller.rb
60
+ - examples/rails_server/app/controllers/server_controller.rb~
61
+ - examples/rails_server/app/controllers/login_controller.rb~
58
62
  - examples/rails_server/app/helpers/application_helper.rb
63
+ - examples/rails_server/app/helpers/login_helper.rb
64
+ - examples/rails_server/app/helpers/server_helper.rb
59
65
  - examples/rails_server/app/views/layouts
60
66
  - examples/rails_server/app/views/login
61
67
  - examples/rails_server/app/views/server
@@ -65,23 +71,37 @@ files:
65
71
  - examples/rails_server/config/environments
66
72
  - examples/rails_server/config/database.yml
67
73
  - examples/rails_server/config/routes.rb
68
- - examples/rails_server/config/environment.rb
69
74
  - examples/rails_server/config/boot.rb
70
- - examples/rails_server/config/environments/test.rb
75
+ - examples/rails_server/config/environment.rb
71
76
  - examples/rails_server/config/environments/production.rb
72
77
  - examples/rails_server/config/environments/development.rb
78
+ - examples/rails_server/config/environments/test.rb
79
+ - examples/rails_server/db/openid-server
80
+ - examples/rails_server/db/openid-store
81
+ - examples/rails_server/db/openid-server/nonces
82
+ - examples/rails_server/db/openid-server/associations
83
+ - examples/rails_server/db/openid-server/temp
84
+ - examples/rails_server/db/openid-store/nonces
85
+ - examples/rails_server/db/openid-store/associations
86
+ - examples/rails_server/db/openid-store/temp
87
+ - examples/rails_server/db/openid-store/associations/http-localhost_2F_7Cnormal-YU.tkND1J4fEZhnuAoT5Zc0yCA0
88
+ - examples/rails_server/db/openid-store/associations/http-localhost_2F_7Cnormal-jRS20gc5OzJ5pkpjy9BjqvTj3B0
73
89
  - examples/rails_server/doc/README_FOR_APP
74
90
  - examples/rails_server/lib/tasks
91
+ - examples/rails_server/log/server.log
92
+ - examples/rails_server/log/production.log
93
+ - examples/rails_server/log/development.log
94
+ - examples/rails_server/log/test.log
75
95
  - examples/rails_server/public/images
76
96
  - examples/rails_server/public/javascripts
77
97
  - examples/rails_server/public/stylesheets
78
- - examples/rails_server/public/favicon.ico
79
- - examples/rails_server/public/robots.txt
80
98
  - examples/rails_server/public/dispatch.rb
81
- - examples/rails_server/public/dispatch.fcgi
82
99
  - examples/rails_server/public/dispatch.cgi
83
- - examples/rails_server/public/500.html
100
+ - examples/rails_server/public/dispatch.fcgi
84
101
  - examples/rails_server/public/404.html
102
+ - examples/rails_server/public/500.html
103
+ - examples/rails_server/public/favicon.ico
104
+ - examples/rails_server/public/robots.txt
85
105
  - examples/rails_server/public/images/rails.png
86
106
  - examples/rails_server/public/javascripts/prototype.js
87
107
  - examples/rails_server/public/javascripts/effects.js
@@ -89,55 +109,82 @@ files:
89
109
  - examples/rails_server/public/javascripts/controls.js
90
110
  - examples/rails_server/script/performance
91
111
  - examples/rails_server/script/process
112
+ - examples/rails_server/script/about
113
+ - examples/rails_server/script/breakpointer
114
+ - examples/rails_server/script/console
115
+ - examples/rails_server/script/destroy
92
116
  - examples/rails_server/script/generate
93
- - examples/rails_server/script/server
94
117
  - examples/rails_server/script/runner
118
+ - examples/rails_server/script/server
95
119
  - examples/rails_server/script/plugin
96
- - examples/rails_server/script/breakpointer
97
- - examples/rails_server/script/destroy
98
- - examples/rails_server/script/console
99
- - examples/rails_server/script/about
100
120
  - examples/rails_server/script/performance/benchmarker
101
121
  - examples/rails_server/script/performance/profiler
102
- - examples/rails_server/script/process/spinner
103
- - examples/rails_server/script/process/spawner
104
122
  - examples/rails_server/script/process/reaper
123
+ - examples/rails_server/script/process/spawner
124
+ - examples/rails_server/script/process/spinner
105
125
  - examples/rails_server/test/fixtures
106
126
  - examples/rails_server/test/functional
107
127
  - examples/rails_server/test/mocks
108
128
  - examples/rails_server/test/unit
109
129
  - examples/rails_server/test/test_helper.rb
110
- - examples/rails_server/test/functional/server_controller_test.rb
111
130
  - examples/rails_server/test/functional/login_controller_test.rb
131
+ - examples/rails_server/test/functional/server_controller_test.rb
112
132
  - examples/rails_server/test/mocks/development
113
133
  - examples/rails_server/test/mocks/test
134
+ - examples/rails_server/tmp/sessions
135
+ - examples/rails_server/tmp/cache
136
+ - examples/rails_server/tmp/sockets
137
+ - examples/rails_server/tmp/sessions/ruby_sess.fb154d2f7c286aba
138
+ - examples/rails_server/tmp/sessions/ruby_sess.968757c6d12af322
139
+ - examples/rails_server/tmp/sessions/ruby_sess.d2ef8fe29591ef9b
140
+ - examples/rails_server/tmp/sessions/ruby_sess.a87a5045744b3abf
141
+ - examples/rails_server/tmp/sessions/ruby_sess.e23240e097e2c83d
142
+ - examples/rails_server/tmp/sessions/ruby_sess.5406e21ba5b1c7bb
143
+ - examples/rails_server/tmp/sessions/ruby_sess.3910508c0c857695
144
+ - examples/rails_server/tmp/sessions/ruby_sess.cf2acf62b93dbc88
145
+ - examples/rails_server/tmp/sessions/ruby_sess.20ed70e0e63d7e31
146
+ - examples/rails_server/tmp/sessions/ruby_sess.cd269e6040645b5b
147
+ - examples/rails_server/tmp/sessions/ruby_sess.1b3584d2b3784c97
148
+ - examples/rails_server/tmp/sessions/ruby_sess.1b2e9635e0f69c0d
149
+ - examples/rails_server/tmp/sessions/ruby_sess.30cf5b98539677d5
150
+ - examples/rails_server/tmp/sessions/ruby_sess.472170ef38098672
151
+ - examples/rails_server/tmp/sessions/ruby_sess.5d2bd2b7086f12d5
152
+ - examples/rails_server/tmp/sessions/ruby_sess.ca9f0a416be0be57
114
153
  - examples/rails_openid_login_generator/templates
115
- - examples/rails_openid_login_generator/gemspec
116
154
  - examples/rails_openid_login_generator/USAGE
117
155
  - examples/rails_openid_login_generator/openid_login_generator.rb
156
+ - examples/rails_openid_login_generator/gemspec
157
+ - examples/rails_openid_login_generator/templates/controller_test.rb
158
+ - examples/rails_openid_login_generator/templates/view_login.rhtml
118
159
  - examples/rails_openid_login_generator/templates/controller.rb
119
160
  - examples/rails_openid_login_generator/templates/README
120
- - examples/rails_openid_login_generator/templates/user_test.rb
121
161
  - examples/rails_openid_login_generator/templates/helper.rb
122
162
  - examples/rails_openid_login_generator/templates/user.rb
123
- - examples/rails_openid_login_generator/templates/view_login.rhtml
124
- - examples/rails_openid_login_generator/templates/users.yml
125
163
  - examples/rails_openid_login_generator/templates/view_logout.rhtml
126
- - examples/rails_openid_login_generator/templates/controller.rb~
127
164
  - examples/rails_openid_login_generator/templates/view_welcome.rhtml
128
- - examples/rails_openid_login_generator/templates/controller_test.rb
165
+ - examples/rails_openid_login_generator/templates/user_test.rb
166
+ - examples/rails_openid_login_generator/templates/users.yml
129
167
  - examples/rails_openid_login_generator/templates/openid_login_system.rb
130
168
  - examples/rails_active_record_store/models
131
- - examples/rails_active_record_store/openidstore_test.rb
132
- - examples/rails_active_record_store/schema.sqlite.sql
133
- - examples/rails_active_record_store/schema.mysql.sql
134
- - examples/rails_active_record_store/schema.postgresql.sql
135
- - examples/rails_active_record_store/openid_helper.rb
136
169
  - examples/rails_active_record_store/README
137
170
  - examples/rails_active_record_store/XX_add_openidstore.rb
138
- - examples/rails_active_record_store/models/openid_setting.rb
139
- - examples/rails_active_record_store/models/openid_nonce.rb
171
+ - examples/rails_active_record_store/openid_helper.rb
172
+ - examples/rails_active_record_store/openidstore_test.rb
173
+ - examples/rails_active_record_store/schema.postgresql.sql
174
+ - examples/rails_active_record_store/schema.mysql.sql
175
+ - examples/rails_active_record_store/schema.sqlite.sql
140
176
  - examples/rails_active_record_store/models/openid_association.rb
177
+ - examples/rails_active_record_store/models/openid_nonce.rb
178
+ - examples/rails_active_record_store/models/openid_setting.rb
179
+ - examples/openid-store/nonces
180
+ - examples/openid-store/associations
181
+ - examples/openid-store/temp
182
+ - examples/openid-store/auth_key
183
+ - examples/openid-store/nonces/PNiw86rQ
184
+ - examples/openid-store/nonces/uHhMdi1i
185
+ - examples/openid-store/nonces/hdZo7WC9
186
+ - examples/openid-store/associations/http-localhost_3A3000_2Fserver-LQl7HUNueJIJcpPoAGiHEHNdJMc
187
+ - examples/openid-store/associations/http-www.myopenid.com_2Fserver-ZFp96P4qV1FjqgGt2rtZBvRJWic
141
188
  - lib/openid
142
189
  - lib/hmac-sha2.rb
143
190
  - lib/hmac.rb
@@ -145,7 +192,6 @@ files:
145
192
  - lib/hmac-rmd160.rb
146
193
  - lib/hmac-md5.rb
147
194
  - lib/openid.rb
148
- - lib/openid/htmltokenizer.rb
149
195
  - lib/openid/consumer.rb
150
196
  - lib/openid/dh.rb
151
197
  - lib/openid/fetchers.rb
@@ -153,25 +199,31 @@ files:
153
199
  - lib/openid/parse.rb
154
200
  - lib/openid/stores.rb
155
201
  - lib/openid/util.rb
202
+ - lib/openid/server.rb
156
203
  - lib/openid/association.rb
157
204
  - lib/openid/trustroot.rb
158
- - lib/openid/server.rb
159
205
  - lib/openid/discovery.rb
206
+ - lib/openid/htmltokenizer.rb
160
207
  - lib/openid/service.rb
208
+ - lib/openid/stores.rb~
209
+ - lib/openid/urinorm.rb
210
+ - lib/openid/discovery.rb~
161
211
  - test/storetestcase.rb
162
212
  - test/linkparse.rb
163
213
  - test/assoc.rb
164
214
  - test/dh.rb
165
215
  - test/teststore.rb
166
- - test/data
167
216
  - test/util.rb
217
+ - test/data
168
218
  - test/trustroot.rb
169
- - test/runtests.rb~
170
- - test/runtests.rb
171
219
  - test/extensions.rb
172
- - test/server2.rb
173
220
  - test/consumer.rb
221
+ - test/runtests.rb
222
+ - test/server2.rb
174
223
  - test/service.rb
224
+ - test/teststore.rb~
225
+ - test/urinorm.rb
226
+ - test/data/urinorm.txt
175
227
  - test/data/brian.xrds
176
228
  - README
177
229
  - INSTALL
@@ -1,111 +0,0 @@
1
- require "pathname"
2
- require "cgi"
3
-
4
- # load the openid library
5
- begin
6
- require "rubygems"
7
- require_gem "ruby-openid", ">= 1.0"
8
- rescue LoadError
9
- require "openid"
10
- end
11
-
12
- class <%= class_name %>Controller < ApplicationController
13
- layout 'scaffold'
14
-
15
- # process the login request, disover the openid server, and
16
- # then redirect.
17
- def login
18
- openid_url = @params[:openid_url]
19
-
20
- if @request.post?
21
- request = consumer.begin(openid_url)
22
-
23
- case request.status
24
- when OpenID::SUCCESS
25
- return_to = url_for(:action=> 'complete')
26
- trust_root = url_for(:controller=>'')
27
-
28
- url = request.redirect_url(trust_root, return_to)
29
- redirect_to(url)
30
- return
31
-
32
- when OpenID::FAILURE
33
- escaped_url = CGI::escape(openid_url)
34
- flash[:notice] = "Could not find OpenID server for #{escaped_url}"
35
-
36
- else
37
- flash[:notice] = "An unknown error occured."
38
-
39
- end
40
- end
41
-
42
- end
43
-
44
- # handle the openid server response
45
- def complete
46
- response = consumer.complete(@params)
47
-
48
- case response.status
49
- when OpenID::SUCCESS
50
-
51
- @user = User.get(response.identity_url)
52
-
53
- # create user object if one does not exist
54
- if @user.nil?
55
- @user = User.new(:openid_url => response.identity_url)
56
- @user.save
57
- end
58
-
59
- # storing both the openid_url and user id in the session for for quick
60
- # access to both bits of information. Change as needed.
61
- @session[:user_id] = @user.id
62
-
63
- flash[:notice] = "Logged in as #{CGI::escape(response.identity_url)}"
64
-
65
- redirect_to :action => "welcome"
66
- return
67
-
68
- when OpenID::FAILURE
69
- if response.identity_url
70
- flash[:notice] = "Verification of #{CGI::escape(response.identity_url)} failed."
71
-
72
- else
73
- flash[:notice] = 'Verification failed.'
74
- end
75
-
76
- when OpenID::CANCEL
77
- flash[:notice] = 'Verification cancelled.'
78
-
79
- else
80
- flash[:notice] = 'Unknown response from OpenID server.'
81
- end
82
-
83
- redirect_to :action => 'login'
84
- end
85
-
86
- def logout
87
- @session[:user_id] = nil
88
- end
89
-
90
- def welcome
91
- end
92
-
93
- private
94
-
95
- # Get the OpenID::Consumer object.
96
- def consumer
97
- # create the OpenID store for storing associations and nonces,
98
- # putting it in your app's db directory
99
- store_dir = Pathname.new(RAILS_ROOT).join('db').join('openid-store')
100
- store = OpenID::FilesystemStore.new(store_dir)
101
-
102
- return OpenID::Consumer.new(@session, store)
103
- end
104
-
105
- # get the logged in user object
106
- def find_user
107
- return nil if session[:user_id].nil?
108
- User.find(session[:user_id])
109
- end
110
-
111
- end