Codebase list ruby-omniauth-twitter / e83ff39
Merge pull request #107 from bzf/al-allow-custom-callback-url Allow passing a callback_url param Rashmi Yadav authored 7 years ago GitHub committed 7 years ago
2 changed file(s) with 62 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
6060 old_request_phase
6161 end
6262
63 alias :old_callback_url :callback_url
64
65 def callback_url
66 if request.params['callback_url']
67 request.params['callback_url']
68 else
69 old_callback_url
70 end
71 end
72
73 def callback_path
74 params = session['omniauth.params']
75
76 if params.nil? || params['callback_url'].nil?
77 super
78 else
79 URI(params['callback_url']).path
80 end
81 end
82
6383 private
6484
6585 def image_url
126126
127127 it "should switch authorize_path from authenticate to authorize" do
128128 expect { subject.request_phase }.to change { subject.options.client_options.authorize_path }.from('/oauth/authenticate').to('/oauth/authorize')
129 end
130 end
131
132 context 'with a specified callback_url in the params' do
133 before do
134 params = { 'callback_url' => 'http://foo.dev/auth/twitter/foobar' }
135 allow(subject).to receive(:request) do
136 double('Request', :params => params)
137 end
138 allow(subject).to receive(:session) do
139 double('Session', :[] => { 'callback_url' => params['callback_url'] })
140 end
141 allow(subject).to receive(:old_request_phase) { :whatever }
142 end
143
144 it 'should use the callback_url' do
145 expect(subject.callback_url).to eq 'http://foo.dev/auth/twitter/foobar'
146 end
147
148 it 'should return the correct callback_path' do
149 expect(subject.callback_path).to eq '/auth/twitter/foobar'
150 end
151 end
152
153 context 'with no callback_url set' do
154 before do
155 allow(subject).to receive(:request) do
156 double('Request', :params => {})
157 end
158 allow(subject).to receive(:session) do
159 double('Session', :[] => {})
160 end
161 allow(subject).to receive(:old_request_phase) { :whatever }
162 allow(subject).to receive(:old_callback_url).and_return(:old_callback)
163 end
164
165 it 'callback_url should return nil' do
166 expect(subject.callback_url).to eq :old_callback
167 end
168
169 it 'should return the default callback_path value' do
170 expect(subject.callback_path).to eq '/auth/twitter/callback'
129171 end
130172 end
131173