Class: EasyRackOpenId::Processing
- Inherits:
-
Object
- Object
- EasyRackOpenId::Processing
- 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 = {}) ⇒ Processing
constructor
A new instance of Processing.
- #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 = {}) ⇒ Processing
Returns a new instance of Processing.
6 7 8 9 |
# File 'lib/easy-rack-open-id/processing.rb', line 6 def initialize(app, ={}) @app = app @options = end |
Instance Attribute Details
#env ⇒ Object
Returns the value of attribute env.
4 5 6 |
# File 'lib/easy-rack-open-id/processing.rb', line 4 def env @env end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/easy-rack-open-id/processing.rb', line 4 def @options end |
Instance Method Details
#after_logout_path ⇒ Object
129 130 131 |
# File 'lib/easy-rack-open-id/processing.rb', line 129 def after_logout_path [:after_logout_path] end |
#allowed? ⇒ Boolean
100 101 102 103 104 105 106 107 108 |
# File 'lib/easy-rack-open-id/processing.rb', line 100 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
114 115 116 |
# File 'lib/easy-rack-open-id/processing.rb', line 114 def allowed_identifiers [:allowed_identifiers] end |
#asset? ⇒ Boolean
29 30 31 |
# File 'lib/easy-rack-open-id/processing.rb', line 29 def asset? 0 == path.index(asset_prefix) end |
#asset_prefix ⇒ Object
33 34 35 |
# File 'lib/easy-rack-open-id/processing.rb', line 33 def asset_prefix '/easy-rack-open-id-assets' end |
#call(env) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/easy-rack-open-id/processing.rb', line 11 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
186 187 188 |
# File 'lib/easy-rack-open-id/processing.rb', line 186 def default_return_to [:default_return_to] || '/' end |
#forward_to(url) ⇒ Object
96 97 98 |
# File 'lib/easy-rack-open-id/processing.rb', line 96 def forward_to(url) [302, {'Location' => url,'Content-Type' => 'text/html'}, ["Forwarding to #{url}"]] end |
#gem_public_path ⇒ Object
37 38 39 |
# File 'lib/easy-rack-open-id/processing.rb', line 37 def gem_public_path File.dirname(__FILE__) + '/../../public/' end |
#identitifier_to_verify ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/easy-rack-open-id/processing.rb', line 137 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
110 111 112 |
# File 'lib/easy-rack-open-id/processing.rb', line 110 def identity_match [:identity_match] end |
#login_path ⇒ Object
133 134 135 |
# File 'lib/easy-rack-open-id/processing.rb', line 133 def login_path [:login_path] end |
#logout ⇒ Object
122 123 124 125 126 127 |
# File 'lib/easy-rack-open-id/processing.rb', line 122 def logout self.verified_identity = nil if after_logout_path forward_to(after_logout_path) end end |
#logout_path ⇒ Object
118 119 120 |
# File 'lib/easy-rack-open-id/processing.rb', line 118 def logout_path [:logout_path] || '/logout' end |
#ok(text, content_type = 'text/html') ⇒ Object
190 191 192 |
# File 'lib/easy-rack-open-id/processing.rb', line 190 def ok(text, content_type = 'text/html') [200,{"Content-Type" => content_type, 'Content-Length'=> text.length.to_s},[text]] end |
#open_id_login ⇒ Object
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 73 |
# File 'lib/easy-rack-open-id/processing.rb', line 41 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
75 76 77 |
# File 'lib/easy-rack-open-id/processing.rb', line 75 def path env['PATH_INFO'] end |
#present_login_options ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/easy-rack-open-id/processing.rb', line 79 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
182 183 184 |
# File 'lib/easy-rack-open-id/processing.rb', line 182 def protected_path session['return_to'] || default_return_to end |
#protected_path=(path) ⇒ Object
178 179 180 |
# File 'lib/easy-rack-open-id/processing.rb', line 178 def protected_path=(path) session['return_to'] = path end |
#session ⇒ Object
174 175 176 |
# File 'lib/easy-rack-open-id/processing.rb', line 174 def session env['rack.session'] end |
#valid_identifier? ⇒ Boolean
152 153 154 155 156 157 158 159 160 |
# File 'lib/easy-rack-open-id/processing.rb', line 152 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
170 171 172 |
# File 'lib/easy-rack-open-id/processing.rb', line 170 def verified_identifier verified_identity && verified_identity['identifier'] end |
#verified_identity ⇒ Object
166 167 168 |
# File 'lib/easy-rack-open-id/processing.rb', line 166 def verified_identity session['verified_identity'] end |
#verified_identity=(hash) ⇒ Object
162 163 164 |
# File 'lib/easy-rack-open-id/processing.rb', line 162 def verified_identity=(hash) session['verified_identity'] = hash end |