1
0
Fork 0
mirror of https://github.com/omniauth/omniauth.git synced 2022-11-09 12:31:49 -05:00

Adds :form option for custom form endpoints.

This commit is contained in:
Michael Bleigh 2011-10-03 14:24:39 -05:00
parent 90875e4600
commit dfb77bfd89
2 changed files with 13 additions and 14 deletions

View file

@ -177,13 +177,15 @@ module OmniAuth
# Performs the steps necessary to run the request phase of a strategy. # Performs the steps necessary to run the request phase of a strategy.
def request_call def request_call
setup_phase setup_phase
if response = call_through_to_app if options.form.respond_to?(:call)
response options.form.call(env)
elsif options.form
call_app!
else else
if request.params['origin'] if request.params['origin']
@env['rack.session']['omniauth.origin'] = request.params['origin'] env['rack.session']['omniauth.origin'] = request.params['origin']
elsif env['HTTP_REFERER'] && !env['HTTP_REFERER'].match(/#{request_path}$/) elsif env['HTTP_REFERER'] && !env['HTTP_REFERER'].match(/#{request_path}$/)
@env['rack.session']['omniauth.origin'] = env['HTTP_REFERER'] env['rack.session']['omniauth.origin'] = env['HTTP_REFERER']
end end
request_phase request_phase
end end

View file

@ -353,18 +353,15 @@ describe OmniAuth::Strategy do
end end
end end
context 'pre-request call through' do context ':form option' do
subject { ExampleStrategy.new(app) } it 'should call through to the supplied form option if one exists' do
let(:app){ lambda{|env| env['omniauth.boom'] = true; [env['test.status'] || 404, {}, ['Whatev']] } } strategy.options.form = lambda{|env| "Called me!"}
it 'should be able to modify the env on the fly before the request_phase' do strategy.call(make_env('/auth/test')).should == "Called me!"
lambda{ subject.call(make_env) }.should raise_error("Request Phase")
subject.response.status.should == 404
subject.last_env.should be_key('omniauth.boom')
end end
it 'should call through to the app instead if a non-404 response is received' do it 'should call through to the app if :form => true is set as an option' do
lambda{ subject.call(make_env('/auth/test', 'test.status' => 200)) }.should_not raise_error strategy.options.form = true
subject.response.body.should == ['Whatev'] strategy.call(make_env('/auth/test')).should == app.call(make_env('/auth/test'))
end end
end end