mirror of
https://github.com/omniauth/omniauth.git
synced 2022-11-09 12:31:49 -05:00
Setup phase is only called on OmniAuth endpoints. Closes #231
This commit is contained in:
parent
e6d0d4e790
commit
6a48fdb89d
2 changed files with 15 additions and 2 deletions
|
@ -28,10 +28,10 @@ module OmniAuth
|
||||||
@env = env
|
@env = env
|
||||||
@env['omniauth.strategy'] = self
|
@env['omniauth.strategy'] = self
|
||||||
|
|
||||||
setup_phase
|
|
||||||
return mock_call!(env) if OmniAuth.config.test_mode
|
return mock_call!(env) if OmniAuth.config.test_mode
|
||||||
|
|
||||||
if current_path == request_path && OmniAuth.config.allowed_request_methods.include?(request.request_method.downcase.to_sym)
|
if current_path == request_path && OmniAuth.config.allowed_request_methods.include?(request.request_method.downcase.to_sym)
|
||||||
|
setup_phase
|
||||||
if response = call_through_to_app
|
if response = call_through_to_app
|
||||||
response
|
response
|
||||||
else
|
else
|
||||||
|
@ -43,6 +43,7 @@ module OmniAuth
|
||||||
request_phase
|
request_phase
|
||||||
end
|
end
|
||||||
elsif current_path == callback_path
|
elsif current_path == callback_path
|
||||||
|
setup_phase
|
||||||
@env['omniauth.origin'] = session.delete('omniauth.origin')
|
@env['omniauth.origin'] = session.delete('omniauth.origin')
|
||||||
@env['omniauth.origin'] = nil if env['omniauth.origin'] == ''
|
@env['omniauth.origin'] = nil if env['omniauth.origin'] == ''
|
||||||
|
|
||||||
|
@ -58,6 +59,7 @@ module OmniAuth
|
||||||
|
|
||||||
def mock_call!(env)
|
def mock_call!(env)
|
||||||
if current_path == request_path
|
if current_path == request_path
|
||||||
|
setup_phase
|
||||||
if response = call_through_to_app
|
if response = call_through_to_app
|
||||||
response
|
response
|
||||||
else
|
else
|
||||||
|
@ -69,6 +71,7 @@ module OmniAuth
|
||||||
redirect(callback_path)
|
redirect(callback_path)
|
||||||
end
|
end
|
||||||
elsif current_path == callback_path
|
elsif current_path == callback_path
|
||||||
|
setup_phase
|
||||||
mocked_auth = OmniAuth.mock_auth_for(name.to_sym)
|
mocked_auth = OmniAuth.mock_auth_for(name.to_sym)
|
||||||
if mocked_auth.is_a?(Symbol)
|
if mocked_auth.is_a?(Symbol)
|
||||||
fail!(mocked_auth)
|
fail!(mocked_auth)
|
||||||
|
|
|
@ -307,12 +307,17 @@ describe OmniAuth::Strategy do
|
||||||
context 'setup phase' do
|
context 'setup phase' do
|
||||||
context 'when options[:setup] = true' do
|
context 'when options[:setup] = true' do
|
||||||
let(:strategy){ ExampleStrategy.new(app, 'test', :setup => true) }
|
let(:strategy){ ExampleStrategy.new(app, 'test', :setup => true) }
|
||||||
let(:app){lambda{|env| env['omniauth.strategy'].options[:awesome] = 'sauce'; [404, {}, 'Awesome']}}
|
let(:app){lambda{|env| env['omniauth.strategy'].options[:awesome] = 'sauce' if env['PATH_INFO'] == '/auth/test/setup'; [404, {}, 'Awesome'] }}
|
||||||
|
|
||||||
it 'should call through to /auth/:provider/setup' do
|
it 'should call through to /auth/:provider/setup' do
|
||||||
strategy.call(make_env('/auth/test'))
|
strategy.call(make_env('/auth/test'))
|
||||||
strategy.options[:awesome].should == 'sauce'
|
strategy.options[:awesome].should == 'sauce'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should not call through on a non-omniauth endpoint' do
|
||||||
|
strategy.call(make_env('/somewhere/else'))
|
||||||
|
strategy.options[:awesome].should_not == 'sauce'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when options[:setup] is an app' do
|
context 'when options[:setup] is an app' do
|
||||||
|
@ -324,6 +329,11 @@ describe OmniAuth::Strategy do
|
||||||
|
|
||||||
let(:strategy){ ExampleStrategy.new(app, 'test', :setup => setup_proc) }
|
let(:strategy){ ExampleStrategy.new(app, 'test', :setup => setup_proc) }
|
||||||
|
|
||||||
|
it 'should not call the app on a non-omniauth endpoint' do
|
||||||
|
strategy.call(make_env('/somehwere/else'))
|
||||||
|
strategy.options[:awesome].should_not == 'sauce'
|
||||||
|
end
|
||||||
|
|
||||||
it 'should call the rack app' do
|
it 'should call the rack app' do
|
||||||
strategy.call(make_env('/auth/test'))
|
strategy.call(make_env('/auth/test'))
|
||||||
strategy.options[:awesome].should == 'sauce'
|
strategy.options[:awesome].should == 'sauce'
|
||||||
|
|
Loading…
Reference in a new issue