Adds 'origin' param to default failure redirect. Closes #569

This commit is contained in:
Michael Bleigh 2012-03-20 21:47:03 -04:00
parent 98fac7bc6d
commit bcd891aec4
2 changed files with 12 additions and 1 deletions

View File

@ -27,8 +27,13 @@ module OmniAuth
def redirect_to_failure
message_key = env['omniauth.error.type']
new_path = "#{env['SCRIPT_NAME']}#{OmniAuth.config.path_prefix}/failure?message=#{message_key}"
new_path = "#{env['SCRIPT_NAME']}#{OmniAuth.config.path_prefix}/failure?message=#{message_key}#{origin_query_param}"
Rack::Response.new(["302 Moved"], 302, 'Location' => new_path).finish
end
def origin_query_param
return "" unless env['omniauth.origin']
"&origin=#{CGI.escape(env['omniauth.origin'])}"
end
end
end

View File

@ -41,5 +41,11 @@ describe OmniAuth::FailureEndpoint do
status, head, body = *subject.call(env)
head["Location"].should == '/boo/failure?message=invalid_request'
end
it 'should include the origin (escaped) if one is provided' do
env.merge! 'omniauth.origin' => '/origin-example'
status, head, body = *subject.call(env)
head['Location'].should be_include('&origin=%2Forigin-example')
end
end
end