Class: EasyRackOpenIDProcessing
- Inherits:
-
Object
- Object
- EasyRackOpenIDProcessing
- Defined in:
- lib/easy_rack_open_id_processing.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
Returns the value of attribute env.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #after_logout_path ⇒ Object
- #allowed? ⇒ Boolean
- #allowed_identifiers ⇒ Object
- #asset? ⇒ Boolean
- #asset_prefix ⇒ Object
- #call(env) ⇒ Object
- #default_return_to ⇒ Object
- #forward_to(url) ⇒ Object
- #gem_public_path ⇒ Object
- #identitifier_to_verify ⇒ Object
- #identity_match ⇒ Object
-
#initialize(app, options = {}) ⇒ EasyRackOpenIDProcessing
constructor
A new instance of EasyRackOpenIDProcessing.
- #login_path ⇒ Object
- #logout ⇒ Object
- #logout_path ⇒ Object
- #ok(text, content_type = 'text/html') ⇒ Object
- #open_id_login ⇒ Object
- #path ⇒ Object
- #present_login_options ⇒ Object
- #protected_path ⇒ Object
- #protected_path=(path) ⇒ Object
- #session ⇒ Object
- #valid_identifier? ⇒ Boolean
- #verified_identifier ⇒ Object
- #verified_identity ⇒ Object
- #verified_identity=(hash) ⇒ Object
Constructor Details
#initialize(app, options = {}) ⇒ EasyRackOpenIDProcessing
Returns a new instance of EasyRackOpenIDProcessing.
5 6 7 8 |
# File 'lib/easy_rack_open_id_processing.rb', line 5 def initialize(app, ={}) @app = app @options = end |
Instance Attribute Details
#env ⇒ Object
Returns the value of attribute env.
3 4 5 |
# File 'lib/easy_rack_open_id_processing.rb', line 3 def env @env end |
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/easy_rack_open_id_processing.rb', line 3 def @options end |
Instance Method Details
#after_logout_path ⇒ Object
128 129 130 |
# File 'lib/easy_rack_open_id_processing.rb', line 128 def after_logout_path [:after_logout_path] end |
#allowed? ⇒ Boolean
99 100 101 102 103 104 105 106 107 |
# File 'lib/easy_rack_open_id_processing.rb', line 99 def allowed? if allowed_identifiers allowed_identifiers.include? verified_identifier elsif identity_match identity_match === verified_identifier else verified_identifier end end |
#allowed_identifiers ⇒ Object
113 114 115 |
# File 'lib/easy_rack_open_id_processing.rb', line 113 def allowed_identifiers [:allowed_identifiers] end |
#asset? ⇒ Boolean
28 29 30 |
# File 'lib/easy_rack_open_id_processing.rb', line 28 def asset? 0 == path.index(asset_prefix) end |
#asset_prefix ⇒ Object
32 33 34 |
# File 'lib/easy_rack_open_id_processing.rb', line 32 def asset_prefix '/easy-rack-openid-assets' end |
#call(env) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/easy_rack_open_id_processing.rb', line 10 def call(env) @env = env if logout_path == path logout_result = logout return logout_result if logout_result end if asset? content_type_lookup = {'css' => 'text/css','html'=> 'text/html','js'=>'text/javascript','gif'=>'image/gif','ico' => 'image/vnd.microsoft.icon', 'png'=> 'image/png'} ok(IO.read(gem_public_path + path), content_type_lookup[File.extname(path)[1..-1]]) elsif allowed? # pass through @app.call(env) else # break chain, start open_id_login open_id_login end end |
#default_return_to ⇒ Object
185 186 187 |
# File 'lib/easy_rack_open_id_processing.rb', line 185 def default_return_to [:default_return_to] || '/' end |
#forward_to(url) ⇒ Object
95 96 97 |
# File 'lib/easy_rack_open_id_processing.rb', line 95 def forward_to(url) [302, {'Location' => url,'Content-Type' => 'text/html'}, ["Forwarding to #{url}"]] end |
#gem_public_path ⇒ Object
36 37 38 |
# File 'lib/easy_rack_open_id_processing.rb', line 36 def gem_public_path File.dirname(__FILE__) + '/../public/' end |
#identitifier_to_verify ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/easy_rack_open_id_processing.rb', line 136 def identitifier_to_verify @identitifier_to_verify ||= if env["rack.request.query_hash"] && env["rack.request.query_hash"]["openid_identifier"] env["rack.request.query_hash"]["openid_identifier"] elsif posted_data = CGI.parse(env['rack.input'].read) env['rack.input'].rewind identifier = posted_data['openid_identifier'] if identifier.kind_of? Array identifier.last else identifier end end end |
#identity_match ⇒ Object
109 110 111 |
# File 'lib/easy_rack_open_id_processing.rb', line 109 def identity_match [:identity_match] end |
#login_path ⇒ Object
132 133 134 |
# File 'lib/easy_rack_open_id_processing.rb', line 132 def login_path [:login_path] end |
#logout ⇒ Object
121 122 123 124 125 126 |
# File 'lib/easy_rack_open_id_processing.rb', line 121 def logout self.verified_identity = nil if after_logout_path forward_to(after_logout_path) end end |
#logout_path ⇒ Object
117 118 119 |
# File 'lib/easy_rack_open_id_processing.rb', line 117 def logout_path [:logout_path] || '/logout' end |
#ok(text, content_type = 'text/html') ⇒ Object
189 190 191 |
# File 'lib/easy_rack_open_id_processing.rb', line 189 def ok(text, content_type = 'text/html') [200,{"Content-Type" => content_type, 'Content-Length'=> text.length.to_s},[text]] end |
#open_id_login ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/easy_rack_open_id_processing.rb', line 40 def open_id_login if resp = env["rack.openid.response"] case resp.status when :success # Load in any registration data gathered profile_data = {} # merge the SReg data and the AX data into a single hash of profile data [ OpenID::SReg::Response, OpenID::AX::FetchResponse ].each do |data_response| if data_response.from_success_response( resp ) profile_data.merge! data_response.from_success_response( resp ).data end end profile_data['identifier'] = resp.identity_url #... save id and registration and forward to ... self.verified_identity = profile_data forward_to(protected_path) when :failure end else if identitifier_to_verify && valid_identifier? self.protected_path = path header_hash = {:identifier => identitifier_to_verify} header_hash.merge!(:required => [:required]) if [:required] header_hash.merge!(:required => [:optional]) if [:optional] header_hash.merge!(:required => [:policy_url]) if [:policy_url] [401, {"WWW-Authenticate" => Rack::OpenID.build_header(header_hash)}, []] else end end end |
#path ⇒ Object
74 75 76 |
# File 'lib/easy_rack_open_id_processing.rb', line 74 def path env['REQUEST_PATH'] end |
#present_login_options ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/easy_rack_open_id_processing.rb', line 78 def if login_path forward_to(login_path) else dir = File.dirname(__FILE__) form = case [:form] when 'boring' IO.read(dir + '/generic_openid_form.html.erb') when 'selector' IO.read(dir + '/nice_openid_form.html.erb') else # use default, real-openid selector IO.read(dir + '/nicer_openid_form.html.erb') end ok(form) end end |
#protected_path ⇒ Object
181 182 183 |
# File 'lib/easy_rack_open_id_processing.rb', line 181 def protected_path session['return_to'] || default_return_to end |
#protected_path=(path) ⇒ Object
177 178 179 |
# File 'lib/easy_rack_open_id_processing.rb', line 177 def protected_path=(path) session['return_to'] = path end |
#session ⇒ Object
173 174 175 |
# File 'lib/easy_rack_open_id_processing.rb', line 173 def session env['rack.session'] end |
#valid_identifier? ⇒ Boolean
151 152 153 154 155 156 157 158 159 |
# File 'lib/easy_rack_open_id_processing.rb', line 151 def valid_identifier? uri = URI.parse(identitifier_to_verify.to_s.strip) uri = URI.parse("http://#{uri}") unless uri.scheme uri.scheme = uri.scheme.downcase # URI should do this uri.normalize.to_s rescue URI::InvalidURIError # raise InvalidOpenId.new("#{url} is not an OpenID URL") false # Quietly fail for now. end |
#verified_identifier ⇒ Object
169 170 171 |
# File 'lib/easy_rack_open_id_processing.rb', line 169 def verified_identifier verified_identity && verified_identity['identifier'] end |
#verified_identity ⇒ Object
165 166 167 |
# File 'lib/easy_rack_open_id_processing.rb', line 165 def verified_identity session['verified_identity'] end |
#verified_identity=(hash) ⇒ Object
161 162 163 |
# File 'lib/easy_rack_open_id_processing.rb', line 161 def verified_identity=(hash) session['verified_identity'] = hash end |