Skip to content

Commit

Permalink
Adds 'origin' param to default failure redirect. Closes #569
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Bleigh committed Mar 21, 2012
1 parent 98fac7b commit bcd891a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/omniauth/failure_endpoint.rb
Expand Up @@ -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
6 changes: 6 additions & 0 deletions spec/omniauth/failure_endpoint_spec.rb
Expand Up @@ -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

0 comments on commit bcd891a

Please sign in to comment.