Skip to content

Commit

Permalink
Override the callback_path method
Browse files Browse the repository at this point in the history
  • Loading branch information
bzf committed Jan 27, 2017
1 parent 8cb9074 commit 4b6122a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/omniauth/strategies/twitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,17 @@ def request_phase
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
Expand Down
41 changes: 41 additions & 0 deletions spec/omniauth/strategies/twitter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,47 @@
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

context "with no request params set and force_login specified" do
before do
allow(subject).to receive(:request) do
Expand Down

0 comments on commit 4b6122a

Please sign in to comment.