From bcd891aec40ca66016600d418371d6df0885cce4 Mon Sep 17 00:00:00 2001 From: Michael Bleigh Date: Tue, 20 Mar 2012 21:47:03 -0400 Subject: [PATCH] Adds 'origin' param to default failure redirect. Closes #569 --- lib/omniauth/failure_endpoint.rb | 7 ++++++- spec/omniauth/failure_endpoint_spec.rb | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/omniauth/failure_endpoint.rb b/lib/omniauth/failure_endpoint.rb index ff248abdd..b6ee176cd 100644 --- a/lib/omniauth/failure_endpoint.rb +++ b/lib/omniauth/failure_endpoint.rb @@ -27,8 +27,13 @@ def raise_out! 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 \ No newline at end of file diff --git a/spec/omniauth/failure_endpoint_spec.rb b/spec/omniauth/failure_endpoint_spec.rb index af97596c0..dc25e60e3 100644 --- a/spec/omniauth/failure_endpoint_spec.rb +++ b/spec/omniauth/failure_endpoint_spec.rb @@ -41,5 +41,11 @@ 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 \ No newline at end of file