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.
def request_call
setup_phase
if response = call_through_to_app
response
if options.form.respond_to?(:call)
options.form.call(env)
elsif options.form
call_app!
else
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}$/)
@env['rack.session']['omniauth.origin'] = env['HTTP_REFERER']
env['rack.session']['omniauth.origin'] = env['HTTP_REFERER']
end
request_phase
end

View File

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