Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing a callback_url param #107

Merged
merged 3 commits into from
Feb 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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