Permalink
Browse files

add support for generating openid check_immediate requests by passing…

… 'immediate' param. added test to ensure setup_needed response can be handled properly. should have test for successful immediate request response. need to update rots to support successful immediate request responses.
  • Loading branch information...
1 parent 7c9f9cf commit cb4a1228d03234d57a067dd11698ad90626eda77 @tquackenbush tquackenbush committed Feb 25, 2011
Showing with 23 additions and 3 deletions.
  1. +5 −3 lib/rack/openid.rb
  2. +18 −0 test/test_openid.rb
View
@@ -118,12 +118,14 @@ def begin_authentication(env, qs)
consumer = ::OpenID::Consumer.new(session, @store)
identifier = params['identifier'] || params['identity']
+ is_immediate_req = params["immediate"] && !params["immediate"].empty?
+
begin
oidreq = consumer.begin(identifier)
add_simple_registration_fields(oidreq, params)
add_attribute_exchange_fields(oidreq, params)
add_oauth_fields(oidreq, params)
- url = open_id_redirect_url(req, oidreq, params["trust_root"], params["return_to"], params["method"])
+ url = open_id_redirect_url(req, oidreq, params["trust_root"], params["return_to"], params["method"], is_immediate_req)
return redirect_to(url)
rescue ::OpenID::OpenIDError, Timeout::Error => e
env[RESPONSE] = MissingResponse.new
@@ -204,7 +206,7 @@ def redirect_to(url)
[303, {"Content-Type" => "text/html", "Location" => url}, []]
end
- def open_id_redirect_url(req, oidreq, trust_root = nil, return_to = nil, method = nil)
+ def open_id_redirect_url(req, oidreq, trust_root = nil, return_to = nil, method = nil, immediate = false)
request_url = request_url(req)
if return_to
@@ -216,7 +218,7 @@ def open_id_redirect_url(req, oidreq, trust_root = nil, return_to = nil, method
method = method.to_s.downcase
oidreq.return_to_args['_method'] = method unless method == "get"
- oidreq.redirect_url(trust_root || realm_url(req), return_to || request_url)
+ oidreq.redirect_url(trust_root || realm_url(req), return_to || request_url, immediate)
end
def add_simple_registration_fields(oidreq, fields)
View
@@ -250,6 +250,21 @@ def test_with_oauth
assert_equal 'success', @response.body
end
+ def test_with_immediate_mode_setup_needed
+ @app = app(:identifier => "#{RotsServerUrl}/john.doe?openid.success=false", :immediate => true)
+ process('/', :method => 'GET')
+
+ location = @response.headers['Location']
+ assert_match(/openid.mode=checkid_immediate/, location)
+
+ follow_redirect!
+ assert_equal 307, @response.status
+ assert_equal 'GET', @response.headers['X-Method']
+ assert_equal '/', @response.headers['X-Path']
+ assert_equal RotsServerUrl, @response.headers['Location']
+ assert_equal 'setup_needed', @response.body
+ end
+
def test_with_missing_id
@app = app(:identifier => "#{RotsServerUrl}/john.doe")
process('/', :method => 'GET')
@@ -297,6 +312,9 @@ def app(options = {})
}
if resp.status == :success
[200, headers, [resp.status.to_s]]
+ elsif resp.status == :setup_needed
+ headers['Location'] = RotsServerUrl #TODO update Rots to properly send user_setup_url. This should come from resp.
+ [307, headers, [resp.status.to_s]]
else
[400, headers, [resp.status.to_s]]
end

0 comments on commit cb4a122

Please sign in to comment.