diff --git a/lib/omniauth.rb b/lib/omniauth.rb index d729019..10b0aaf 100644 --- a/lib/omniauth.rb +++ b/lib/omniauth.rb @@ -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, diff --git a/spec/omniauth/strategy_spec.rb b/spec/omniauth/strategy_spec.rb index 19b8d8d..aa9b8ae 100644 --- a/spec/omniauth/strategy_spec.rb +++ b/spec/omniauth/strategy_spec.rb @@ -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