Skip to content

Commit

Permalink
redirect back to original path to clear openid query string
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Jul 25, 2010
1 parent bc9d5a4 commit 6330efa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 11 additions & 1 deletion lib/rack/openid/simple_auth.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'rack/openid'
require 'rack/request'

module Rack #:nodoc:
class OpenID
Expand Down Expand Up @@ -26,7 +27,7 @@ def call(env)
app.call(env)
elsif successful_response?(env)
authenticate_session(env)
app.call(env)
redirect_to requested_url(env)
else
authentication_request
end
Expand Down Expand Up @@ -55,6 +56,15 @@ def successful_response?(env)
end
end

def requested_url(env)
req = Rack::Request.new(env)
req.url
end

def redirect_to(url)
[303, {'Content-Type' => 'text/html', 'Location' => url}, []]
end

def authentication_request
[401, { OpenID::AUTHENTICATE_HEADER => www_authenticate_header }, []]
end
Expand Down
5 changes: 3 additions & 2 deletions test/test_openid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,13 @@ def test_successful_login
process '/dashboard'
follow_redirect!

assert_equal 200, @response.status
assert_equal 'Hello', @response.body
assert_equal 303, @response.status
assert_equal 'http://example.org/dashboard', @response.headers['Location']

cookie = @response.headers['Set-Cookie'].split(';').first
process '/dashboard', 'HTTP_COOKIE' => cookie
assert_equal 200, @response.status
assert_equal 'Hello', @response.body
end

def test_failed_login
Expand Down

0 comments on commit 6330efa

Please sign in to comment.