diff --git a/lib/omniauth/strategies/twitter.rb b/lib/omniauth/strategies/twitter.rb index 6f83a8d..3d890b6 100644 --- a/lib/omniauth/strategies/twitter.rb +++ b/lib/omniauth/strategies/twitter.rb @@ -62,7 +62,17 @@ end def callback_url - request.params['callback_url'] || super + request.params['callback_url'] + end + + def callback_path + params = session['omniauth.params'] + + if params.nil? || params['callback_url'].nil? + super + else + URI(params['callback_url']).path + end end private diff --git a/spec/omniauth/strategies/twitter_spec.rb b/spec/omniauth/strategies/twitter_spec.rb index 3cb0e92..08d726f 100644 --- a/spec/omniauth/strategies/twitter_spec.rb +++ b/spec/omniauth/strategies/twitter_spec.rb @@ -127,6 +127,47 @@ it "should switch authorize_path from authenticate to authorize" do expect { subject.request_phase }.to change { subject.options.client_options.authorize_path }.from('/oauth/authenticate').to('/oauth/authorize') + end + end + + context 'with a specified callback_url in the params' do + before do + params = { 'callback_url' => 'http://foo.dev/auth/twitter/foobar' } + allow(subject).to receive(:request) do + double('Request', :params => params) + end + allow(subject).to receive(:session) do + double('Session', :[] => { 'callback_url' => params['callback_url'] }) + end + allow(subject).to receive(:old_request_phase) { :whatever } + end + + it 'should use the callback_url' do + expect(subject.callback_url).to eq 'http://foo.dev/auth/twitter/foobar' + end + + it 'should return the correct callback_path' do + expect(subject.callback_path).to eq '/auth/twitter/foobar' + end + end + + context 'with no callback_url set' do + before do + allow(subject).to receive(:request) do + double('Request', :params => {}) + end + allow(subject).to receive(:session) do + double('Session', :[] => {}) + end + allow(subject).to receive(:old_request_phase) { :whatever } + end + + it 'callback_url should return nil' do + expect(subject.callback_url).to be_nil + end + + it 'should return the default callback_path value' do + expect(subject.callback_path).to eq '/auth/twitter/callback' end end