entp-ruby-openid 2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +215 -0
- data/INSTALL +47 -0
- data/LICENSE +210 -0
- data/NOTICE +2 -0
- data/README +85 -0
- data/UPGRADE +127 -0
- data/admin/runtests.rb +45 -0
- data/examples/README +32 -0
- data/examples/active_record_openid_store/README +58 -0
- data/examples/active_record_openid_store/XXX_add_open_id_store_to_db.rb +24 -0
- data/examples/active_record_openid_store/XXX_upgrade_open_id_store.rb +26 -0
- data/examples/active_record_openid_store/init.rb +8 -0
- data/examples/active_record_openid_store/lib/association.rb +10 -0
- data/examples/active_record_openid_store/lib/nonce.rb +3 -0
- data/examples/active_record_openid_store/lib/open_id_setting.rb +4 -0
- data/examples/active_record_openid_store/lib/openid_ar_store.rb +57 -0
- data/examples/active_record_openid_store/test/store_test.rb +212 -0
- data/examples/discover +49 -0
- data/examples/rails_openid/README +153 -0
- data/examples/rails_openid/Rakefile +10 -0
- data/examples/rails_openid/app/controllers/application.rb +4 -0
- data/examples/rails_openid/app/controllers/consumer_controller.rb +125 -0
- data/examples/rails_openid/app/controllers/login_controller.rb +45 -0
- data/examples/rails_openid/app/controllers/server_controller.rb +265 -0
- data/examples/rails_openid/app/helpers/application_helper.rb +3 -0
- data/examples/rails_openid/app/helpers/login_helper.rb +2 -0
- data/examples/rails_openid/app/helpers/server_helper.rb +9 -0
- data/examples/rails_openid/app/views/consumer/index.rhtml +81 -0
- data/examples/rails_openid/app/views/layouts/server.rhtml +68 -0
- data/examples/rails_openid/app/views/login/index.rhtml +56 -0
- data/examples/rails_openid/app/views/server/decide.rhtml +26 -0
- data/examples/rails_openid/config/boot.rb +19 -0
- data/examples/rails_openid/config/database.yml +74 -0
- data/examples/rails_openid/config/environment.rb +54 -0
- data/examples/rails_openid/config/environments/development.rb +19 -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/routes.rb +24 -0
- data/examples/rails_openid/doc/README_FOR_APP +2 -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/hmac/hmac.rb +112 -0
- data/lib/hmac/sha1.rb +11 -0
- data/lib/hmac/sha2.rb +25 -0
- data/lib/openid.rb +22 -0
- data/lib/openid/association.rb +249 -0
- data/lib/openid/consumer.rb +395 -0
- data/lib/openid/consumer/associationmanager.rb +344 -0
- data/lib/openid/consumer/checkid_request.rb +186 -0
- data/lib/openid/consumer/discovery.rb +497 -0
- data/lib/openid/consumer/discovery_manager.rb +123 -0
- data/lib/openid/consumer/html_parse.rb +134 -0
- data/lib/openid/consumer/idres.rb +523 -0
- data/lib/openid/consumer/responses.rb +150 -0
- data/lib/openid/cryptutil.rb +115 -0
- data/lib/openid/dh.rb +89 -0
- data/lib/openid/extension.rb +39 -0
- data/lib/openid/extensions/ax.rb +539 -0
- data/lib/openid/extensions/oauth.rb +91 -0
- data/lib/openid/extensions/pape.rb +179 -0
- data/lib/openid/extensions/sreg.rb +277 -0
- data/lib/openid/extras.rb +11 -0
- data/lib/openid/fetchers.rb +258 -0
- data/lib/openid/kvform.rb +136 -0
- data/lib/openid/kvpost.rb +58 -0
- data/lib/openid/message.rb +553 -0
- data/lib/openid/protocolerror.rb +12 -0
- data/lib/openid/server.rb +1544 -0
- data/lib/openid/store.rb +10 -0
- data/lib/openid/store/filesystem.rb +272 -0
- data/lib/openid/store/interface.rb +75 -0
- data/lib/openid/store/memcache.rb +109 -0
- data/lib/openid/store/memory.rb +84 -0
- data/lib/openid/store/nonce.rb +68 -0
- data/lib/openid/trustroot.rb +349 -0
- data/lib/openid/urinorm.rb +75 -0
- data/lib/openid/util.rb +119 -0
- data/lib/openid/version.rb +3 -0
- data/lib/openid/yadis.rb +15 -0
- data/lib/openid/yadis/accept.rb +148 -0
- data/lib/openid/yadis/constants.rb +21 -0
- data/lib/openid/yadis/discovery.rb +153 -0
- data/lib/openid/yadis/filters.rb +205 -0
- data/lib/openid/yadis/htmltokenizer.rb +305 -0
- data/lib/openid/yadis/parsehtml.rb +45 -0
- data/lib/openid/yadis/services.rb +42 -0
- data/lib/openid/yadis/xrds.rb +155 -0
- data/lib/openid/yadis/xri.rb +90 -0
- data/lib/openid/yadis/xrires.rb +91 -0
- data/test/data/test_discover/openid_utf8.html +11 -0
- data/test/support/test_data_mixin.rb +127 -0
- data/test/support/test_util.rb +53 -0
- data/test/support/yadis_data.rb +131 -0
- data/test/support/yadis_data/accept.txt +124 -0
- data/test/support/yadis_data/dh.txt +29 -0
- data/test/support/yadis_data/example-xrds.xml +14 -0
- data/test/support/yadis_data/linkparse.txt +587 -0
- data/test/support/yadis_data/n2b64 +650 -0
- data/test/support/yadis_data/test1-discover.txt +137 -0
- data/test/support/yadis_data/test1-parsehtml.txt +152 -0
- data/test/support/yadis_data/test_discover/malformed_meta_tag.html +19 -0
- data/test/support/yadis_data/test_discover/openid.html +11 -0
- data/test/support/yadis_data/test_discover/openid2.html +11 -0
- data/test/support/yadis_data/test_discover/openid2_xrds.xml +12 -0
- data/test/support/yadis_data/test_discover/openid2_xrds_no_local_id.xml +11 -0
- data/test/support/yadis_data/test_discover/openid_1_and_2.html +11 -0
- data/test/support/yadis_data/test_discover/openid_1_and_2_xrds.xml +16 -0
- data/test/support/yadis_data/test_discover/openid_1_and_2_xrds_bad_delegate.xml +17 -0
- data/test/support/yadis_data/test_discover/openid_and_yadis.html +12 -0
- data/test/support/yadis_data/test_discover/openid_no_delegate.html +10 -0
- data/test/support/yadis_data/test_discover/openid_utf8.html +11 -0
- data/test/support/yadis_data/test_discover/yadis_0entries.xml +12 -0
- data/test/support/yadis_data/test_discover/yadis_2_bad_local_id.xml +15 -0
- data/test/support/yadis_data/test_discover/yadis_2entries_delegate.xml +22 -0
- data/test/support/yadis_data/test_discover/yadis_2entries_idp.xml +21 -0
- data/test/support/yadis_data/test_discover/yadis_another_delegate.xml +14 -0
- data/test/support/yadis_data/test_discover/yadis_idp.xml +12 -0
- data/test/support/yadis_data/test_discover/yadis_idp_delegate.xml +13 -0
- data/test/support/yadis_data/test_discover/yadis_no_delegate.xml +11 -0
- data/test/support/yadis_data/test_xrds/=j3h.2007.11.14.xrds +25 -0
- data/test/support/yadis_data/test_xrds/README +12 -0
- data/test/support/yadis_data/test_xrds/delegated-20060809-r1.xrds +34 -0
- data/test/support/yadis_data/test_xrds/delegated-20060809-r2.xrds +34 -0
- data/test/support/yadis_data/test_xrds/delegated-20060809.xrds +34 -0
- data/test/support/yadis_data/test_xrds/no-xrd.xml +7 -0
- data/test/support/yadis_data/test_xrds/not-xrds.xml +2 -0
- data/test/support/yadis_data/test_xrds/prefixsometimes.xrds +34 -0
- data/test/support/yadis_data/test_xrds/ref.xrds +109 -0
- data/test/support/yadis_data/test_xrds/sometimesprefix.xrds +34 -0
- data/test/support/yadis_data/test_xrds/spoof1.xrds +25 -0
- data/test/support/yadis_data/test_xrds/spoof2.xrds +25 -0
- data/test/support/yadis_data/test_xrds/spoof3.xrds +37 -0
- data/test/support/yadis_data/test_xrds/status222.xrds +9 -0
- data/test/support/yadis_data/test_xrds/subsegments.xrds +58 -0
- data/test/support/yadis_data/test_xrds/valid-populated-xrds.xml +39 -0
- data/test/support/yadis_data/trustroot.txt +153 -0
- data/test/support/yadis_data/urinorm.txt +79 -0
- data/test/test_accept.rb +170 -0
- data/test/test_association.rb +268 -0
- data/test/test_associationmanager.rb +918 -0
- data/test/test_ax.rb +690 -0
- data/test/test_checkid_request.rb +293 -0
- data/test/test_consumer.rb +260 -0
- data/test/test_cryptutil.rb +119 -0
- data/test/test_dh.rb +85 -0
- data/test/test_discover.rb +848 -0
- data/test/test_discovery_manager.rb +259 -0
- data/test/test_extension.rb +46 -0
- data/test/test_extras.rb +35 -0
- data/test/test_fetchers.rb +554 -0
- data/test/test_filters.rb +269 -0
- data/test/test_helper.rb +4 -0
- data/test/test_idres.rb +961 -0
- data/test/test_kvform.rb +164 -0
- data/test/test_kvpost.rb +64 -0
- data/test/test_linkparse.rb +100 -0
- data/test/test_message.rb +1115 -0
- data/test/test_nonce.rb +89 -0
- data/test/test_oauth.rb +176 -0
- data/test/test_openid_yadis.rb +177 -0
- data/test/test_pape.rb +248 -0
- data/test/test_parsehtml.rb +79 -0
- data/test/test_responses.rb +63 -0
- data/test/test_server.rb +2455 -0
- data/test/test_sreg.rb +479 -0
- data/test/test_stores.rb +292 -0
- data/test/test_trustroot.rb +111 -0
- data/test/test_urinorm.rb +34 -0
- data/test/test_util.rb +145 -0
- data/test/test_xrds.rb +167 -0
- data/test/test_xri.rb +48 -0
- data/test/test_xrires.rb +67 -0
- data/test/test_yadis_discovery.rb +218 -0
- metadata +268 -0
@@ -0,0 +1,45 @@
|
|
1
|
+
# Controller for handling the login, logout process for "users" of our
|
2
|
+
# little server. Users have no password. This is just an example.
|
3
|
+
|
4
|
+
require 'openid'
|
5
|
+
|
6
|
+
class LoginController < ApplicationController
|
7
|
+
|
8
|
+
layout 'server'
|
9
|
+
|
10
|
+
def base_url
|
11
|
+
url_for(:controller => 'login', :action => nil, :only_path => false)
|
12
|
+
end
|
13
|
+
|
14
|
+
def index
|
15
|
+
response.headers['X-XRDS-Location'] = url_for(:controller => "server",
|
16
|
+
:action => "idp_xrds",
|
17
|
+
:only_path => false)
|
18
|
+
@base_url = base_url
|
19
|
+
# just show the login page
|
20
|
+
end
|
21
|
+
|
22
|
+
def submit
|
23
|
+
user = params[:username]
|
24
|
+
|
25
|
+
# if we get a user, log them in by putting their username in
|
26
|
+
# the session hash.
|
27
|
+
unless user.nil?
|
28
|
+
session[:username] = user unless user.nil?
|
29
|
+
session[:approvals] = []
|
30
|
+
flash[:notice] = "Your OpenID URL is <b>#{base_url}user/#{user}</b><br/><br/>Proceed to step 2 below."
|
31
|
+
else
|
32
|
+
flash[:error] = "Sorry, couldn't log you in. Try again."
|
33
|
+
end
|
34
|
+
|
35
|
+
redirect_to :action => 'index'
|
36
|
+
end
|
37
|
+
|
38
|
+
def logout
|
39
|
+
# delete the username from the session hash
|
40
|
+
session[:username] = nil
|
41
|
+
session[:approvals] = nil
|
42
|
+
redirect_to :action => 'index'
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,265 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
# load the openid library, first trying rubygems
|
4
|
+
#begin
|
5
|
+
# require "rubygems"
|
6
|
+
# require_gem "ruby-openid", ">= 1.0"
|
7
|
+
#rescue LoadError
|
8
|
+
require "openid"
|
9
|
+
require "openid/consumer/discovery"
|
10
|
+
require 'openid/extensions/sreg'
|
11
|
+
require 'openid/extensions/pape'
|
12
|
+
require 'openid/store/filesystem'
|
13
|
+
#end
|
14
|
+
|
15
|
+
class ServerController < ApplicationController
|
16
|
+
|
17
|
+
include ServerHelper
|
18
|
+
include OpenID::Server
|
19
|
+
layout nil
|
20
|
+
|
21
|
+
def index
|
22
|
+
begin
|
23
|
+
oidreq = server.decode_request(params)
|
24
|
+
rescue ProtocolError => e
|
25
|
+
# invalid openid request, so just display a page with an error message
|
26
|
+
render :text => e.to_s, :status => 500
|
27
|
+
return
|
28
|
+
end
|
29
|
+
|
30
|
+
# no openid.mode was given
|
31
|
+
unless oidreq
|
32
|
+
render :text => "This is an OpenID server endpoint."
|
33
|
+
return
|
34
|
+
end
|
35
|
+
|
36
|
+
oidresp = nil
|
37
|
+
|
38
|
+
if oidreq.kind_of?(CheckIDRequest)
|
39
|
+
|
40
|
+
identity = oidreq.identity
|
41
|
+
|
42
|
+
if oidreq.id_select
|
43
|
+
if oidreq.immediate
|
44
|
+
oidresp = oidreq.answer(false)
|
45
|
+
elsif session[:username].nil?
|
46
|
+
# The user hasn't logged in.
|
47
|
+
show_decision_page(oidreq)
|
48
|
+
return
|
49
|
+
else
|
50
|
+
# Else, set the identity to the one the user is using.
|
51
|
+
identity = url_for_user
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
if oidresp
|
56
|
+
nil
|
57
|
+
elsif self.is_authorized(identity, oidreq.trust_root)
|
58
|
+
oidresp = oidreq.answer(true, nil, identity)
|
59
|
+
|
60
|
+
# add the sreg response if requested
|
61
|
+
add_sreg(oidreq, oidresp)
|
62
|
+
# ditto pape
|
63
|
+
add_pape(oidreq, oidresp)
|
64
|
+
|
65
|
+
elsif oidreq.immediate
|
66
|
+
server_url = url_for :action => 'index'
|
67
|
+
oidresp = oidreq.answer(false, server_url)
|
68
|
+
|
69
|
+
else
|
70
|
+
show_decision_page(oidreq)
|
71
|
+
return
|
72
|
+
end
|
73
|
+
|
74
|
+
else
|
75
|
+
oidresp = server.handle_request(oidreq)
|
76
|
+
end
|
77
|
+
|
78
|
+
self.render_response(oidresp)
|
79
|
+
end
|
80
|
+
|
81
|
+
def show_decision_page(oidreq, message="Do you trust this site with your identity?")
|
82
|
+
session[:last_oidreq] = oidreq
|
83
|
+
@oidreq = oidreq
|
84
|
+
|
85
|
+
if message
|
86
|
+
flash[:notice] = message
|
87
|
+
end
|
88
|
+
|
89
|
+
render :template => 'server/decide', :layout => 'server'
|
90
|
+
end
|
91
|
+
|
92
|
+
def user_page
|
93
|
+
# Yadis content-negotiation: we want to return the xrds if asked for.
|
94
|
+
accept = request.env['HTTP_ACCEPT']
|
95
|
+
|
96
|
+
# This is not technically correct, and should eventually be updated
|
97
|
+
# to do real Accept header parsing and logic. Though I expect it will work
|
98
|
+
# 99% of the time.
|
99
|
+
if accept and accept.include?('application/xrds+xml')
|
100
|
+
user_xrds
|
101
|
+
return
|
102
|
+
end
|
103
|
+
|
104
|
+
# content negotiation failed, so just render the user page
|
105
|
+
xrds_url = url_for(:controller=>'user',:action=>params[:username])+'/xrds'
|
106
|
+
identity_page = <<EOS
|
107
|
+
<html><head>
|
108
|
+
<meta http-equiv="X-XRDS-Location" content="#{xrds_url}" />
|
109
|
+
<link rel="openid.server" href="#{url_for :action => 'index'}" />
|
110
|
+
</head><body><p>OpenID identity page for #{params[:username]}</p>
|
111
|
+
</body></html>
|
112
|
+
EOS
|
113
|
+
|
114
|
+
# Also add the Yadis location header, so that they don't have
|
115
|
+
# to parse the html unless absolutely necessary.
|
116
|
+
response.headers['X-XRDS-Location'] = xrds_url
|
117
|
+
render :text => identity_page
|
118
|
+
end
|
119
|
+
|
120
|
+
def user_xrds
|
121
|
+
types = [
|
122
|
+
OpenID::OPENID_2_0_TYPE,
|
123
|
+
OpenID::OPENID_1_0_TYPE,
|
124
|
+
OpenID::SREG_URI,
|
125
|
+
]
|
126
|
+
|
127
|
+
render_xrds(types)
|
128
|
+
end
|
129
|
+
|
130
|
+
def idp_xrds
|
131
|
+
types = [
|
132
|
+
OpenID::OPENID_IDP_2_0_TYPE,
|
133
|
+
]
|
134
|
+
|
135
|
+
render_xrds(types)
|
136
|
+
end
|
137
|
+
|
138
|
+
def decision
|
139
|
+
oidreq = session[:last_oidreq]
|
140
|
+
session[:last_oidreq] = nil
|
141
|
+
|
142
|
+
if params[:yes].nil?
|
143
|
+
redirect_to oidreq.cancel_url
|
144
|
+
return
|
145
|
+
else
|
146
|
+
id_to_send = params[:id_to_send]
|
147
|
+
|
148
|
+
identity = oidreq.identity
|
149
|
+
if oidreq.id_select
|
150
|
+
if id_to_send and id_to_send != ""
|
151
|
+
session[:username] = id_to_send
|
152
|
+
session[:approvals] = []
|
153
|
+
identity = url_for_user
|
154
|
+
else
|
155
|
+
msg = "You must enter a username to in order to send " +
|
156
|
+
"an identifier to the Relying Party."
|
157
|
+
show_decision_page(oidreq, msg)
|
158
|
+
return
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
if session[:approvals]
|
163
|
+
session[:approvals] << oidreq.trust_root
|
164
|
+
else
|
165
|
+
session[:approvals] = [oidreq.trust_root]
|
166
|
+
end
|
167
|
+
oidresp = oidreq.answer(true, nil, identity)
|
168
|
+
add_sreg(oidreq, oidresp)
|
169
|
+
add_pape(oidreq, oidresp)
|
170
|
+
return self.render_response(oidresp)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
protected
|
175
|
+
|
176
|
+
def server
|
177
|
+
if @server.nil?
|
178
|
+
server_url = url_for :action => 'index', :only_path => false
|
179
|
+
dir = Pathname.new(RAILS_ROOT).join('db').join('openid-store')
|
180
|
+
store = OpenID::Store::Filesystem.new(dir)
|
181
|
+
@server = Server.new(store, server_url)
|
182
|
+
end
|
183
|
+
return @server
|
184
|
+
end
|
185
|
+
|
186
|
+
def approved(trust_root)
|
187
|
+
return false if session[:approvals].nil?
|
188
|
+
return session[:approvals].member?(trust_root)
|
189
|
+
end
|
190
|
+
|
191
|
+
def is_authorized(identity_url, trust_root)
|
192
|
+
return (session[:username] and (identity_url == url_for_user) and self.approved(trust_root))
|
193
|
+
end
|
194
|
+
|
195
|
+
def render_xrds(types)
|
196
|
+
type_str = ""
|
197
|
+
|
198
|
+
types.each { |uri|
|
199
|
+
type_str += "<Type>#{uri}</Type>\n "
|
200
|
+
}
|
201
|
+
|
202
|
+
yadis = <<EOS
|
203
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
204
|
+
<xrds:XRDS
|
205
|
+
xmlns:xrds="xri://$xrds"
|
206
|
+
xmlns="xri://$xrd*($v*2.0)">
|
207
|
+
<XRD>
|
208
|
+
<Service priority="0">
|
209
|
+
#{type_str}
|
210
|
+
<URI>#{url_for(:controller => 'server', :only_path => false)}</URI>
|
211
|
+
</Service>
|
212
|
+
</XRD>
|
213
|
+
</xrds:XRDS>
|
214
|
+
EOS
|
215
|
+
|
216
|
+
response.headers['content-type'] = 'application/xrds+xml'
|
217
|
+
render :text => yadis
|
218
|
+
end
|
219
|
+
|
220
|
+
def add_sreg(oidreq, oidresp)
|
221
|
+
# check for Simple Registration arguments and respond
|
222
|
+
sregreq = OpenID::SReg::Request.from_openid_request(oidreq)
|
223
|
+
|
224
|
+
return if sregreq.nil?
|
225
|
+
# In a real application, this data would be user-specific,
|
226
|
+
# and the user should be asked for permission to release
|
227
|
+
# it.
|
228
|
+
sreg_data = {
|
229
|
+
'nickname' => session[:username],
|
230
|
+
'fullname' => 'Mayor McCheese',
|
231
|
+
'email' => 'mayor@example.com'
|
232
|
+
}
|
233
|
+
|
234
|
+
sregresp = OpenID::SReg::Response.extract_response(sregreq, sreg_data)
|
235
|
+
oidresp.add_extension(sregresp)
|
236
|
+
end
|
237
|
+
|
238
|
+
def add_pape(oidreq, oidresp)
|
239
|
+
papereq = OpenID::PAPE::Request.from_openid_request(oidreq)
|
240
|
+
return if papereq.nil?
|
241
|
+
paperesp = OpenID::PAPE::Response.new
|
242
|
+
paperesp.nist_auth_level = 0 # we don't even do auth at all!
|
243
|
+
oidresp.add_extension(paperesp)
|
244
|
+
end
|
245
|
+
|
246
|
+
def render_response(oidresp)
|
247
|
+
if oidresp.needs_signing
|
248
|
+
signed_response = server.signatory.sign(oidresp)
|
249
|
+
end
|
250
|
+
web_response = server.encode_response(oidresp)
|
251
|
+
|
252
|
+
case web_response.code
|
253
|
+
when HTTP_OK
|
254
|
+
render :text => web_response.body, :status => 200
|
255
|
+
|
256
|
+
when HTTP_REDIRECT
|
257
|
+
redirect_to web_response.headers['location']
|
258
|
+
|
259
|
+
else
|
260
|
+
render :text => web_response.body, :status => 400
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
|
265
|
+
end
|
@@ -0,0 +1,81 @@
|
|
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
|
+
</style>
|
41
|
+
<body>
|
42
|
+
<h1>Rails OpenID Example Relying Party</h1>
|
43
|
+
<% if flash[:alert] %>
|
44
|
+
<div class='alert'>
|
45
|
+
<%= h(flash[:alert]) %>
|
46
|
+
</div>
|
47
|
+
<% end %>
|
48
|
+
<% if flash[:error] %>
|
49
|
+
<div class='error'>
|
50
|
+
<%= h(flash[:error]) %>
|
51
|
+
</div>
|
52
|
+
<% end %>
|
53
|
+
<% if flash[:success] %>
|
54
|
+
<div class='success'>
|
55
|
+
<%= h(flash[:success]) %>
|
56
|
+
</div>
|
57
|
+
<% end %>
|
58
|
+
<% if flash[:sreg_results] %>
|
59
|
+
<div class='alert'>
|
60
|
+
<%= flash[:sreg_results] %>
|
61
|
+
</div>
|
62
|
+
<% end %>
|
63
|
+
<% if flash[:pape_results] %>
|
64
|
+
<div class='alert'>
|
65
|
+
<%= flash[:pape_results] %>
|
66
|
+
</div>
|
67
|
+
<% end %>
|
68
|
+
<div id="verify-form">
|
69
|
+
<form method="get" accept-charset="UTF-8"
|
70
|
+
action='<%= url_for :action => 'start' %>'>
|
71
|
+
Identifier:
|
72
|
+
<input type="text" class="openid" name="openid_identifier" />
|
73
|
+
<input type="submit" value="Verify" /><br />
|
74
|
+
<input type="checkbox" name="immediate" id="immediate" /><label for="immediate">Use immediate mode</label><br/>
|
75
|
+
<input type="checkbox" name="use_sreg" id="use_sreg" /><label for="use_sreg">Request registration data</label><br/>
|
76
|
+
<input type="checkbox" name="use_pape" id="use_pape" /><label for="use_pape">Request phishing-resistent auth policy (PAPE)</label><br/>
|
77
|
+
<input type="checkbox" name="force_post" id="force_post" /><label for="force_post">Force the transaction to use POST by adding 2K of extra data</label>
|
78
|
+
</form>
|
79
|
+
</div>
|
80
|
+
</body>
|
81
|
+
</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>
|