From dfb77bfd89c57c39e2549381819dd42b2f5c35d2 Mon Sep 17 00:00:00 2001 From: Michael Bleigh Date: Mon, 3 Oct 2011 14:24:39 -0500 Subject: [PATCH] Adds :form option for custom form endpoints. --- lib/omniauth/strategy.rb | 10 ++++++---- spec/omniauth/strategy_spec.rb | 17 +++++++---------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/omniauth/strategy.rb b/lib/omniauth/strategy.rb index b027b7e..7c024d4 100644 --- a/lib/omniauth/strategy.rb +++ b/lib/omniauth/strategy.rb @@ -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 diff --git a/spec/omniauth/strategy_spec.rb b/spec/omniauth/strategy_spec.rb index 677925b..31ccaae 100644 --- a/spec/omniauth/strategy_spec.rb +++ b/spec/omniauth/strategy_spec.rb @@ -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