From c7ce5fb3e0f4c2e71b51808733ae20bb4aae8711 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Sch=C3=BCrrer?= Date: Fri, 12 Nov 2010 15:02:41 +0100 Subject: [PATCH] Use custom callback_path / prefix_path for callback_url --- oa-core/lib/omniauth/strategy.rb | 4 ++-- oa-core/spec/omniauth/strategy_spec.rb | 33 +++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/oa-core/lib/omniauth/strategy.rb b/oa-core/lib/omniauth/strategy.rb index 0f4e6f990..e678e87fc 100644 --- a/oa-core/lib/omniauth/strategy.rb +++ b/oa-core/lib/omniauth/strategy.rb @@ -81,7 +81,7 @@ def full_host end def callback_url - full_host + "#{OmniAuth.config.path_prefix}/#{name}/callback" + full_host + callback_path end def session @@ -105,4 +105,4 @@ def fail!(message_key, exception = nil) OmniAuth.config.on_failure.call(self.env, message_key.to_sym) end end -end \ No newline at end of file +end diff --git a/oa-core/spec/omniauth/strategy_spec.rb b/oa-core/spec/omniauth/strategy_spec.rb index 17e988241..d41552785 100644 --- a/oa-core/spec/omniauth/strategy_spec.rb +++ b/oa-core/spec/omniauth/strategy_spec.rb @@ -38,6 +38,16 @@ def callback_phase it 'should use the default callback path' do lambda{ strategy.call({'PATH_INFO' => '/auth/test/callback'}) }.should raise_error("Callback Phase") end + + context 'callback_url' do + it 'uses the default callback_path' do + strategy.should_receive(:full_host).and_return('http://example.com') + + lambda{ strategy.call({'PATH_INFO' => '/auth/test'}) }.should raise_error("Request Phase") + + strategy.callback_url.should == 'http://example.com/auth/test/callback' + end + end end it 'should be able to modify the env on the fly before the request_phase' do @@ -59,6 +69,17 @@ def callback_phase @options = {:callback_path => '/radical'} lambda{ strategy.call({'PATH_INFO' => '/radical'}) }.should raise_error("Callback Phase") end + + context 'callback_url' do + it 'uses a custom callback_path if one is provided' do + @options = {:callback_path => '/radical'} + strategy.should_receive(:full_host).and_return('http://example.com') + + lambda{ strategy.call({'PATH_INFO' => '/radical'}) }.should raise_error("Callback Phase") + + strategy.callback_url.should == 'http://example.com/radical' + end + end end context 'custom prefix' do @@ -73,6 +94,16 @@ def callback_phase it 'should use a custom prefix for callback' do lambda{ strategy.call({'PATH_INFO' => '/wowzers/test/callback'}) }.should raise_error("Callback Phase") end + + context 'callback_url' do + it 'uses a custom prefix' do + strategy.should_receive(:full_host).and_return('http://example.com') + + lambda{ strategy.call({'PATH_INFO' => '/wowzers/test'}) }.should raise_error("Request Phase") + + strategy.callback_url.should == 'http://example.com/wowzers/test/callback' + end + end end end -end \ No newline at end of file +end