insert env['SCRIPT_NAME'] before on_failure path

handle sub_uri (a.k.a. BaseURI) at on_failure
This commit is contained in:
Toyokazu Akiyama 2011-12-13 14:54:59 +09:00
parent 2b2384bdf0
commit 9022d66cea
2 changed files with 13 additions and 1 deletions

View File

@ -24,7 +24,7 @@ module OmniAuth
:path_prefix => '/auth',
:on_failure => Proc.new do |env|
message_key = env['omniauth.error.type']
new_path = "#{OmniAuth.config.path_prefix}/failure?message=#{message_key}"
new_path = "#{env['SCRIPT_NAME']}#{OmniAuth.config.path_prefix}/failure?message=#{message_key}"
[302, {'Location' => new_path, 'Content-Type'=> 'text/html'}, []]
end,
:form_css => Form::DEFAULT_CSS,

View File

@ -496,6 +496,18 @@ describe OmniAuth::Strategy do
response[1]['Location'].should == '/sub_uri/auth/test/callback'
end
it 'should redirect on failure' do
response = OmniAuth.config.on_failure.call(make_env('/auth/test', 'omniauth.error.type' => 'error'))
response[0].should == 302
response[1]['Location'].should == '/auth/failure?message=error'
end
it 'should respect SCRIPT_NAME (a.k.a. BaseURI) on failure' do
response = OmniAuth.config.on_failure.call(make_env('/auth/test', 'SCRIPT_NAME' => '/sub_uri', 'omniauth.error.type' => 'error'))
response[0].should == 302
response[1]['Location'].should == '/sub_uri/auth/failure?message=error'
end
it 'should be case insensitive on callback path' do
strategy.call(make_env('/AUTH/TeSt/CaLlBAck')).should == strategy.call(make_env('/auth/test/callback'))
end