Skip to content

Commit

Permalink
Merge pull request #107 from bzf/al-allow-custom-callback-url
Browse files Browse the repository at this point in the history
Allow passing a callback_url param
  • Loading branch information
raysrashmi authored Feb 7, 2017
2 parents 74cc5ca + 7d066d1 commit e83ff39
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/omniauth/strategies/twitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,26 @@ def request_phase
old_request_phase
end

alias :old_callback_url :callback_url

def callback_url
if request.params['callback_url']
request.params['callback_url']
else
old_callback_url
end
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

def image_url
Expand Down
42 changes: 42 additions & 0 deletions spec/omniauth/strategies/twitter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,48 @@
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 }
allow(subject).to receive(:old_callback_url).and_return(:old_callback)
end

it 'callback_url should return nil' do
expect(subject.callback_url).to eq :old_callback
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 e83ff39

Please sign in to comment.