ruby-mojeid 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +22 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/examples/README +32 -0
- data/examples/rails_openid/Gemfile +7 -0
- data/examples/rails_openid/Gemfile.lock +41 -0
- data/examples/rails_openid/README +153 -0
- data/examples/rails_openid/Rakefile +10 -0
- data/examples/rails_openid/app/controllers/application_controller.rb +4 -0
- data/examples/rails_openid/app/controllers/consumer_controller.rb +79 -0
- data/examples/rails_openid/app/views/consumer/index.rhtml +88 -0
- data/examples/rails_openid/app/views/layouts/server.rhtml +68 -0
- data/examples/rails_openid/config/boot.rb +125 -0
- data/examples/rails_openid/config/database.sample.yml +14 -0
- data/examples/rails_openid/config/environment.rb +56 -0
- data/examples/rails_openid/config/environments/development.rb +16 -0
- data/examples/rails_openid/config/environments/production.rb +19 -0
- data/examples/rails_openid/config/environments/test.rb +19 -0
- data/examples/rails_openid/config/preinitializer.rb +20 -0
- data/examples/rails_openid/config/routes.rb +19 -0
- data/examples/rails_openid/public/.htaccess +40 -0
- data/examples/rails_openid/public/404.html +8 -0
- data/examples/rails_openid/public/500.html +8 -0
- data/examples/rails_openid/public/dispatch.cgi +12 -0
- data/examples/rails_openid/public/dispatch.fcgi +26 -0
- data/examples/rails_openid/public/dispatch.rb +12 -0
- data/examples/rails_openid/public/favicon.ico +0 -0
- data/examples/rails_openid/public/images/openid_login_bg.gif +0 -0
- data/examples/rails_openid/public/javascripts/controls.js +750 -0
- data/examples/rails_openid/public/javascripts/dragdrop.js +584 -0
- data/examples/rails_openid/public/javascripts/effects.js +854 -0
- data/examples/rails_openid/public/javascripts/prototype.js +1785 -0
- data/examples/rails_openid/public/robots.txt +1 -0
- data/examples/rails_openid/script/about +3 -0
- data/examples/rails_openid/script/breakpointer +3 -0
- data/examples/rails_openid/script/console +3 -0
- data/examples/rails_openid/script/destroy +3 -0
- data/examples/rails_openid/script/generate +3 -0
- data/examples/rails_openid/script/performance/benchmarker +3 -0
- data/examples/rails_openid/script/performance/profiler +3 -0
- data/examples/rails_openid/script/plugin +3 -0
- data/examples/rails_openid/script/process/reaper +3 -0
- data/examples/rails_openid/script/process/spawner +3 -0
- data/examples/rails_openid/script/process/spinner +3 -0
- data/examples/rails_openid/script/runner +3 -0
- data/examples/rails_openid/script/server +3 -0
- data/examples/rails_openid/test/functional/login_controller_test.rb +18 -0
- data/examples/rails_openid/test/functional/server_controller_test.rb +18 -0
- data/examples/rails_openid/test/test_helper.rb +28 -0
- data/lib/available_attributes.rb +69 -0
- data/lib/ruby-mojeid.rb +106 -0
- data/ruby-mojeid.gemspec +130 -0
- data/test/helper.rb +18 -0
- data/test/test_ruby-mojeid.rb +7 -0
- metadata +230 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
gem "ruby-openid", "2.1.8"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "shoulda", ">= 0"
|
10
|
+
gem "bundler", "~> 1.0.0"
|
11
|
+
gem "jeweler", "~> 1.5.2"
|
12
|
+
gem "rcov", ">= 0"
|
13
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
git (1.2.5)
|
5
|
+
jeweler (1.5.2)
|
6
|
+
bundler (~> 1.0.0)
|
7
|
+
git (>= 1.2.5)
|
8
|
+
rake
|
9
|
+
rake (0.8.7)
|
10
|
+
rcov (0.9.9)
|
11
|
+
ruby-openid (2.1.8)
|
12
|
+
shoulda (2.11.3)
|
13
|
+
|
14
|
+
PLATFORMS
|
15
|
+
ruby
|
16
|
+
|
17
|
+
DEPENDENCIES
|
18
|
+
bundler (~> 1.0.0)
|
19
|
+
jeweler (~> 1.5.2)
|
20
|
+
rcov
|
21
|
+
ruby-openid (= 2.1.8)
|
22
|
+
shoulda
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Robin Bortlik
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= ruby-mojeid
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to ruby-mojeid
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 Robin Bortlik. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "ruby-mojeid"
|
16
|
+
gem.homepage = "http://github.com/robinbortlik/ruby-mojeid"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{This gem help use ruby-openid more simple}
|
19
|
+
gem.description = %Q{This gem extend ruby-openid gem}
|
20
|
+
gem.email = "robinbortlik@gmail.com"
|
21
|
+
gem.authors = ["Robin Bortlik"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
gem.add_runtime_dependency 'ruby-openid', '2.1.8'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rake/testtask'
|
30
|
+
Rake::TestTask.new(:test) do |test|
|
31
|
+
test.libs << 'lib' << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
|
36
|
+
require 'rcov/rcovtask'
|
37
|
+
Rcov::RcovTask.new do |test|
|
38
|
+
test.libs << 'test'
|
39
|
+
test.pattern = 'test/**/test_*.rb'
|
40
|
+
test.verbose = true
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "ruby-mojeid #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.0
|
data/examples/README
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
This directory contains several examples that demonstrate use of the
|
2
|
+
OpenID library. Make sure you have properly installed the library
|
3
|
+
before running the examples. These examples are a great place to
|
4
|
+
start in integrating OpenID into your application.
|
5
|
+
|
6
|
+
==Rails example
|
7
|
+
|
8
|
+
The rails_openid contains a fully functional OpenID server and relying
|
9
|
+
party, and acts as a starting point for implementing your own
|
10
|
+
production rails server. You'll need the latest version of Ruby on
|
11
|
+
Rails installed, and then:
|
12
|
+
|
13
|
+
cd rails_openid
|
14
|
+
./script/server
|
15
|
+
|
16
|
+
Open a web browser to http://localhost:3000/ and follow the instructions.
|
17
|
+
|
18
|
+
The relevant code to work from when writing your Rails OpenID Relying
|
19
|
+
Party is:
|
20
|
+
rails_openid/app/controllers/consumer_controller.rb
|
21
|
+
If you are working on an OpenID provider, check out
|
22
|
+
rails_openid/app/controllers/server_controller.rb
|
23
|
+
|
24
|
+
Since the library and examples are Apache-licensed, don't be shy about
|
25
|
+
copy-and-paste.
|
26
|
+
|
27
|
+
==Rails ActiveRecord OpenIDStore plugin
|
28
|
+
|
29
|
+
For various reasons you may want or need to deploy your ruby openid
|
30
|
+
consumer/server using an SQL based store. The active_record_openid_store
|
31
|
+
is a plugin that makes using an SQL based store simple. Follow the
|
32
|
+
README inside the plugin's dir for usage.
|
@@ -0,0 +1,41 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /home/robin/rails_workspace/ruby-mojeid
|
3
|
+
specs:
|
4
|
+
ruby-mojeid (0.1.0)
|
5
|
+
ruby-openid (= 2.1.8)
|
6
|
+
ruby-openid (= 2.1.8)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
remote: http://gemcutter.com/
|
11
|
+
remote: http://gems.github.com/
|
12
|
+
specs:
|
13
|
+
actionmailer (2.3.9)
|
14
|
+
actionpack (= 2.3.9)
|
15
|
+
actionpack (2.3.9)
|
16
|
+
activesupport (= 2.3.9)
|
17
|
+
rack (~> 1.1.0)
|
18
|
+
activerecord (2.3.9)
|
19
|
+
activesupport (= 2.3.9)
|
20
|
+
activeresource (2.3.9)
|
21
|
+
activesupport (= 2.3.9)
|
22
|
+
activesupport (2.3.9)
|
23
|
+
mysql (2.7)
|
24
|
+
rack (1.1.0)
|
25
|
+
rails (2.3.9)
|
26
|
+
actionmailer (= 2.3.9)
|
27
|
+
actionpack (= 2.3.9)
|
28
|
+
activerecord (= 2.3.9)
|
29
|
+
activeresource (= 2.3.9)
|
30
|
+
activesupport (= 2.3.9)
|
31
|
+
rake (>= 0.8.3)
|
32
|
+
rake (0.8.7)
|
33
|
+
ruby-openid (2.1.8)
|
34
|
+
|
35
|
+
PLATFORMS
|
36
|
+
ruby
|
37
|
+
|
38
|
+
DEPENDENCIES
|
39
|
+
mysql (= 2.7)
|
40
|
+
rails (= 2.3.9)
|
41
|
+
ruby-mojeid!
|
@@ -0,0 +1,153 @@
|
|
1
|
+
== Welcome to Rails
|
2
|
+
|
3
|
+
Rails is a web-application and persistence framework that includes everything
|
4
|
+
needed to create database-backed web-applications according to the
|
5
|
+
Model-View-Control pattern of separation. This pattern splits the view (also
|
6
|
+
called the presentation) into "dumb" templates that are primarily responsible
|
7
|
+
for inserting pre-built data in between HTML tags. The model contains the
|
8
|
+
"smart" domain objects (such as Account, Product, Person, Post) that holds all
|
9
|
+
the business logic and knows how to persist themselves to a database. The
|
10
|
+
controller handles the incoming requests (such as Save New Account, Update
|
11
|
+
Product, Show Post) by manipulating the model and directing data to the view.
|
12
|
+
|
13
|
+
In Rails, the model is handled by what's called an object-relational mapping
|
14
|
+
layer entitled Active Record. This layer allows you to present the data from
|
15
|
+
database rows as objects and embellish these data objects with business logic
|
16
|
+
methods. You can read more about Active Record in
|
17
|
+
link:files/vendor/rails/activerecord/README.html.
|
18
|
+
|
19
|
+
The controller and view are handled by the Action Pack, which handles both
|
20
|
+
layers by its two parts: Action View and Action Controller. These two layers
|
21
|
+
are bundled in a single package due to their heavy interdependence. This is
|
22
|
+
unlike the relationship between the Active Record and Action Pack that is much
|
23
|
+
more separate. Each of these packages can be used independently outside of
|
24
|
+
Rails. You can read more about Action Pack in
|
25
|
+
link:files/vendor/rails/actionpack/README.html.
|
26
|
+
|
27
|
+
|
28
|
+
== Getting started
|
29
|
+
|
30
|
+
1. Run the WEBrick servlet: <tt>ruby script/server</tt> (run with --help for options)
|
31
|
+
...or if you have lighttpd installed: <tt>ruby script/lighttpd</tt> (it's faster)
|
32
|
+
2. Go to http://localhost:3000/ and get "Congratulations, you've put Ruby on Rails!"
|
33
|
+
3. Follow the guidelines on the "Congratulations, you've put Ruby on Rails!" screen
|
34
|
+
|
35
|
+
|
36
|
+
== Example for Apache conf
|
37
|
+
|
38
|
+
<VirtualHost *:80>
|
39
|
+
ServerName rails
|
40
|
+
DocumentRoot /path/application/public/
|
41
|
+
ErrorLog /path/application/log/server.log
|
42
|
+
|
43
|
+
<Directory /path/application/public/>
|
44
|
+
Options ExecCGI FollowSymLinks
|
45
|
+
AllowOverride all
|
46
|
+
Allow from all
|
47
|
+
Order allow,deny
|
48
|
+
</Directory>
|
49
|
+
</VirtualHost>
|
50
|
+
|
51
|
+
NOTE: Be sure that CGIs can be executed in that directory as well. So ExecCGI
|
52
|
+
should be on and ".cgi" should respond. All requests from 127.0.0.1 go
|
53
|
+
through CGI, so no Apache restart is necessary for changes. All other requests
|
54
|
+
go through FCGI (or mod_ruby), which requires a restart to show changes.
|
55
|
+
|
56
|
+
|
57
|
+
== Debugging Rails
|
58
|
+
|
59
|
+
Have "tail -f" commands running on both the server.log, production.log, and
|
60
|
+
test.log files. Rails will automatically display debugging and runtime
|
61
|
+
information to these files. Debugging info will also be shown in the browser
|
62
|
+
on requests from 127.0.0.1.
|
63
|
+
|
64
|
+
|
65
|
+
== Breakpoints
|
66
|
+
|
67
|
+
Breakpoint support is available through the script/breakpointer client. This
|
68
|
+
means that you can break out of execution at any point in the code, investigate
|
69
|
+
and change the model, AND then resume execution! Example:
|
70
|
+
|
71
|
+
class WeblogController < ActionController::Base
|
72
|
+
def index
|
73
|
+
@posts = Post.find_all
|
74
|
+
breakpoint "Breaking out from the list"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
So the controller will accept the action, run the first line, then present you
|
79
|
+
with a IRB prompt in the breakpointer window. Here you can do things like:
|
80
|
+
|
81
|
+
Executing breakpoint "Breaking out from the list" at .../webrick_server.rb:16 in 'breakpoint'
|
82
|
+
|
83
|
+
>> @posts.inspect
|
84
|
+
=> "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
|
85
|
+
#<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
|
86
|
+
>> @posts.first.title = "hello from a breakpoint"
|
87
|
+
=> "hello from a breakpoint"
|
88
|
+
|
89
|
+
...and even better is that you can examine how your runtime objects actually work:
|
90
|
+
|
91
|
+
>> f = @posts.first
|
92
|
+
=> #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
|
93
|
+
>> f.
|
94
|
+
Display all 152 possibilities? (y or n)
|
95
|
+
|
96
|
+
Finally, when you're ready to resume execution, you press CTRL-D
|
97
|
+
|
98
|
+
|
99
|
+
== Console
|
100
|
+
|
101
|
+
You can interact with the domain model by starting the console through script/console.
|
102
|
+
Here you'll have all parts of the application configured, just like it is when the
|
103
|
+
application is running. You can inspect domain models, change values, and save to the
|
104
|
+
database. Starting the script without arguments will launch it in the development environment.
|
105
|
+
Passing an argument will specify a different environment, like <tt>console production</tt>.
|
106
|
+
|
107
|
+
|
108
|
+
== Description of contents
|
109
|
+
|
110
|
+
app
|
111
|
+
Holds all the code that's specific to this particular application.
|
112
|
+
|
113
|
+
app/controllers
|
114
|
+
Holds controllers that should be named like weblog_controller.rb for
|
115
|
+
automated URL mapping. All controllers should descend from
|
116
|
+
ActionController::Base.
|
117
|
+
|
118
|
+
app/models
|
119
|
+
Holds models that should be named like post.rb.
|
120
|
+
Most models will descend from ActiveRecord::Base.
|
121
|
+
|
122
|
+
app/views
|
123
|
+
Holds the template files for the view that should be named like
|
124
|
+
weblog/index.rhtml for the WeblogController#index action. All views use eRuby
|
125
|
+
syntax. This directory can also be used to keep stylesheets, images, and so on
|
126
|
+
that can be symlinked to public.
|
127
|
+
|
128
|
+
app/helpers
|
129
|
+
Holds view helpers that should be named like weblog_helper.rb.
|
130
|
+
|
131
|
+
config
|
132
|
+
Configuration files for the Rails environment, the routing map, the database, and other dependencies.
|
133
|
+
|
134
|
+
components
|
135
|
+
Self-contained mini-applications that can bundle together controllers, models, and views.
|
136
|
+
|
137
|
+
lib
|
138
|
+
Application specific libraries. Basically, any kind of custom code that doesn't
|
139
|
+
belong under controllers, models, or helpers. This directory is in the load path.
|
140
|
+
|
141
|
+
public
|
142
|
+
The directory available for the web server. Contains subdirectories for images, stylesheets,
|
143
|
+
and javascripts. Also contains the dispatchers and the default HTML files.
|
144
|
+
|
145
|
+
script
|
146
|
+
Helper scripts for automation and generation.
|
147
|
+
|
148
|
+
test
|
149
|
+
Unit and functional tests along with fixtures.
|
150
|
+
|
151
|
+
vendor
|
152
|
+
External libraries that the application depends on. Also includes the plugins subdirectory.
|
153
|
+
This directory is in the load path.
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
|
+
# for example lib/tasks/switchtower.rake, and they will automatically be available to Rake.
|
3
|
+
|
4
|
+
require(File.join(File.dirname(__FILE__), 'config', 'boot'))
|
5
|
+
|
6
|
+
require 'rake'
|
7
|
+
require 'rake/testtask'
|
8
|
+
require 'rake/rdoctask'
|
9
|
+
|
10
|
+
require 'tasks/rails'
|
@@ -0,0 +1,79 @@
|
|
1
|
+
class ConsumerController < ApplicationController
|
2
|
+
layout nil
|
3
|
+
|
4
|
+
def index
|
5
|
+
# render an openid form
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
# EXAMPLE HOW TO RETRIEVE DATA FROM MOJEID
|
10
|
+
def start_get_data
|
11
|
+
begin
|
12
|
+
identifier = params[:openid_identifier].to_s + params[:openid_domain].to_s
|
13
|
+
@moje_id = MojeID.fetch_request(consumer, identifier)
|
14
|
+
rescue OpenID::OpenIDError => e
|
15
|
+
flash[:error] = "Discovery failed for #{identifier}: #{e}"
|
16
|
+
return redirect_to :action => 'index'
|
17
|
+
end
|
18
|
+
|
19
|
+
@moje_id.add_attributes(MojeIDAttributes::AVAILABLE_ATTRIBUTES[0..3])
|
20
|
+
@moje_id.return_to = url_for(:action => 'complete_get_data', :only_path => false)
|
21
|
+
@moje_id.realm = url_for(:action => 'index', :id => nil, :only_path => false)
|
22
|
+
redirect_to @moje_id.redirect_url
|
23
|
+
end
|
24
|
+
|
25
|
+
def complete_get_data
|
26
|
+
current_url = url_for(:action => 'complete_get_data', :only_path => false)
|
27
|
+
@moje_id = MojeID.fetch_response(consumer, params, request, current_url)
|
28
|
+
reflect_moje_id_response_status
|
29
|
+
render :action => 'index'
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
# EXAMPLE HOW TO UPDATE DATA TO MOJEID
|
34
|
+
def start_update_data
|
35
|
+
begin
|
36
|
+
identifier = params[:openid_identifier]
|
37
|
+
@moje_id = MojeID.fetch_request(consumer, identifier, :put)
|
38
|
+
rescue OpenID::OpenIDError => e
|
39
|
+
flash[:error] = "Discovery failed for #{identifier}: #{e}"
|
40
|
+
return redirect_to :action => 'index'
|
41
|
+
end
|
42
|
+
|
43
|
+
@moje_id.update_attributes(params[:moje_id_attributes])
|
44
|
+
@moje_id.return_to = url_for(:action => 'complete_update_data', :only_path => false)
|
45
|
+
@moje_id.realm = url_for(:action => 'index', :id => nil, :only_path => false)
|
46
|
+
redirect_to @moje_id.redirect_url
|
47
|
+
end
|
48
|
+
|
49
|
+
def complete_update_data
|
50
|
+
current_url = url_for(:action => 'complete_update_data', :only_path => false)
|
51
|
+
@moje_id = MojeID.fetch_response(consumer, params, request, current_url, :put)
|
52
|
+
reflect_moje_id_response_status
|
53
|
+
render :action => 'index'
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
require 'openid/store/memcache'
|
59
|
+
require 'memcache'
|
60
|
+
|
61
|
+
def consumer
|
62
|
+
if @consumer.nil?
|
63
|
+
store = OpenID::Store::Memcache.new(MemCache.new('localhost:11211'))
|
64
|
+
@consumer = OpenID::Consumer.new(session, store)
|
65
|
+
end
|
66
|
+
return @consumer
|
67
|
+
end
|
68
|
+
|
69
|
+
def reflect_moje_id_response_status
|
70
|
+
case @moje_id.response_status
|
71
|
+
when OpenID::Consumer::FAILURE then flash[:error] = "Verification failed: #{@moje_id.message}"
|
72
|
+
when OpenID::Consumer::SUCCESS then flash[:success] = ("Verification of #{@moje_id.identifier} succeeded.")
|
73
|
+
when OpenID::Consumer::SETUP_NEEDED then flash[:alert] = "Immediate request failed - Setup Needed"
|
74
|
+
when OpenID::Consumer::CANCEL then flash[:alert] = "OpenID transaction cancelled."
|
75
|
+
else
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>Rails OpenID Example Relying Party</title>
|
4
|
+
</head>
|
5
|
+
<style type="text/css">
|
6
|
+
* {
|
7
|
+
font-family: verdana,sans-serif;
|
8
|
+
}
|
9
|
+
body {
|
10
|
+
width: 50em;
|
11
|
+
margin: 1em;
|
12
|
+
}
|
13
|
+
div {
|
14
|
+
padding: .5em;
|
15
|
+
}
|
16
|
+
.alert {
|
17
|
+
border: 1px solid #e7dc2b;
|
18
|
+
background: #fff888;
|
19
|
+
}
|
20
|
+
.error {
|
21
|
+
border: 1px solid #ff0000;
|
22
|
+
background: #ffaaaa;
|
23
|
+
}
|
24
|
+
.success {
|
25
|
+
border: 1px solid #00ff00;
|
26
|
+
background: #aaffaa;
|
27
|
+
}
|
28
|
+
#verify-form {
|
29
|
+
border: 1px solid #777777;
|
30
|
+
background: #dddddd;
|
31
|
+
margin-top: 1em;
|
32
|
+
padding-bottom: 0em;
|
33
|
+
}
|
34
|
+
input.openid {
|
35
|
+
background: url( /images/openid_login_bg.gif ) no-repeat;
|
36
|
+
background-position: 0 50%;
|
37
|
+
background-color: #fff;
|
38
|
+
padding-left: 18px;
|
39
|
+
}
|
40
|
+
|
41
|
+
table tr th {background: #dddddd; text-align: left;}
|
42
|
+
</style>
|
43
|
+
<body>
|
44
|
+
<h1>Rails OpenID Example Relying Party</h1>
|
45
|
+
<% if flash[:alert] %>
|
46
|
+
<div class='alert'>
|
47
|
+
<%= h(flash[:alert]) %>
|
48
|
+
</div>
|
49
|
+
<% end %>
|
50
|
+
<% if flash[:error] %>
|
51
|
+
<div class='error'>
|
52
|
+
<%= h(flash[:error]) %>
|
53
|
+
</div>
|
54
|
+
<% end %>
|
55
|
+
<% if flash[:success] %>
|
56
|
+
<div class='success'>
|
57
|
+
<%= h(flash[:success]) %>
|
58
|
+
</div>
|
59
|
+
<% end %>
|
60
|
+
|
61
|
+
<div id="verify-form">
|
62
|
+
<form method="get" accept-charset="UTF-8" action='<%= url_for :action => 'start_get_data' %>'>
|
63
|
+
Identifier:
|
64
|
+
<%= text_field_tag("openid_identifier", nil, :class => "openid") %>
|
65
|
+
<%= select_tag('openid_domain', options_for_select(['.mojeid.cz'])) %>
|
66
|
+
<%= submit_tag "Get data" %><br />
|
67
|
+
</form>
|
68
|
+
|
69
|
+
<form method="get" accept-charset="UTF-8" action='<%= url_for :action => 'start_update_data' %>'>
|
70
|
+
<% if @moje_id %>
|
71
|
+
<table cellspacing="0">
|
72
|
+
<% MojeIDAttributes::AVAILABLE_ATTRIBUTES[0..3].each do |attribute| %>
|
73
|
+
<tr>
|
74
|
+
<th><%= label_tag("moje_id_attributes[#{attribute}]", attribute) %></th>
|
75
|
+
<td><%= text_field_tag("moje_id_attributes[#{attribute}]", @moje_id.get_attribute_value(attribute)) %></td>
|
76
|
+
</tr>
|
77
|
+
<% end %>
|
78
|
+
<tr>
|
79
|
+
<th></th>
|
80
|
+
<td><%= submit_tag "Save data" %><br /></td>
|
81
|
+
</tr>
|
82
|
+
</table>
|
83
|
+
<%= hidden_field_tag('openid_identifier', @moje_id.identifier) %>
|
84
|
+
<% end %>
|
85
|
+
</form>
|
86
|
+
</div>
|
87
|
+
</body>
|
88
|
+
</html>
|
@@ -0,0 +1,68 @@
|
|
1
|
+
<html>
|
2
|
+
<head><title>OpenID Server Example</title></head>
|
3
|
+
<style type="text/css">
|
4
|
+
* {
|
5
|
+
font-family: verdana,sans-serif;
|
6
|
+
}
|
7
|
+
body {
|
8
|
+
width: 50em;
|
9
|
+
margin: 1em;
|
10
|
+
}
|
11
|
+
div {
|
12
|
+
padding: .5em;
|
13
|
+
}
|
14
|
+
table {
|
15
|
+
margin: none;
|
16
|
+
padding: none;
|
17
|
+
}
|
18
|
+
.notice {
|
19
|
+
border: 1px solid #60964f;
|
20
|
+
background: #b3dca7;
|
21
|
+
}
|
22
|
+
.error {
|
23
|
+
border: 1px solid #ff0000;
|
24
|
+
background: #ffaaaa;
|
25
|
+
}
|
26
|
+
#login-form {
|
27
|
+
border: 1px solid #777777;
|
28
|
+
background: #dddddd;
|
29
|
+
margin-top: 1em;
|
30
|
+
padding-bottom: 0em;
|
31
|
+
}
|
32
|
+
table {
|
33
|
+
padding: 1em;
|
34
|
+
}
|
35
|
+
li {margin-bottom: .5em;}
|
36
|
+
span.openid:before {
|
37
|
+
content: url(<%= @base_url %>images/openid_login_bg.gif) ;
|
38
|
+
}
|
39
|
+
span.openid {
|
40
|
+
font-size: smaller;
|
41
|
+
}
|
42
|
+
</style>
|
43
|
+
<body>
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
<% if session[:username] %>
|
48
|
+
<div style="float:right;">
|
49
|
+
Welcome, <%= session[:username] %> | <%= link_to('Log out', :controller => 'login', :action => 'logout') %><br />
|
50
|
+
<span class="openid"><%= @base_url %>user/<%= session[:username] %></span>
|
51
|
+
</div>
|
52
|
+
<% end %>
|
53
|
+
|
54
|
+
<h3>Ruby OpenID Server Example</h3>
|
55
|
+
|
56
|
+
<hr/>
|
57
|
+
|
58
|
+
<% if flash[:notice] or flash[:error] %>
|
59
|
+
<div class="<%= flash[:notice].nil? ? 'error' : 'notice' %>">
|
60
|
+
<%= flash[:error] or flash[:notice] %>
|
61
|
+
</div>
|
62
|
+
<% end %>
|
63
|
+
|
64
|
+
<%= @content_for_layout %>
|
65
|
+
|
66
|
+
|
67
|
+
</body>
|
68
|
+
</html>
|