mirror of
https://github.com/omniauth/omniauth.git
synced 2022-11-09 12:31:49 -05:00
Origin is preserved in the failure endpoint. Closes #227
This commit is contained in:
parent
4ba963e966
commit
e6d0d4e790
2 changed files with 21 additions and 10 deletions
|
@ -36,15 +36,15 @@ module OmniAuth
|
|||
response
|
||||
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
|
||||
elsif current_path == callback_path
|
||||
env['omniauth.origin'] = session.delete('omniauth.origin')
|
||||
env['omniauth.origin'] = nil if env['omniauth.origin'] == ''
|
||||
@env['omniauth.origin'] = session.delete('omniauth.origin')
|
||||
@env['omniauth.origin'] = nil if env['omniauth.origin'] == ''
|
||||
|
||||
callback_phase
|
||||
else
|
||||
|
@ -62,9 +62,9 @@ module OmniAuth
|
|||
response
|
||||
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
|
||||
redirect(callback_path)
|
||||
end
|
||||
|
@ -74,8 +74,8 @@ module OmniAuth
|
|||
fail!(mocked_auth)
|
||||
else
|
||||
@env['omniauth.auth'] = mocked_auth
|
||||
env['omniauth.origin'] = session.delete('omniauth.origin')
|
||||
env['omniauth.origin'] = nil if env['omniauth.origin'] == ''
|
||||
@env['omniauth.origin'] = session.delete('omniauth.origin')
|
||||
@env['omniauth.origin'] = nil if env['omniauth.origin'] == ''
|
||||
call_app!
|
||||
end
|
||||
else
|
||||
|
@ -192,7 +192,7 @@ module OmniAuth
|
|||
self.env['omniauth.error'] = exception
|
||||
self.env['omniauth.error.type'] = message_key.to_sym
|
||||
self.env['omniauth.error.strategy'] = self
|
||||
|
||||
|
||||
OmniAuth.config.on_failure.call(self.env)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,11 +5,16 @@ class ExampleStrategy
|
|||
def call(env); self.call!(env) end
|
||||
attr_reader :last_env
|
||||
def request_phase
|
||||
@last_env = env
|
||||
@fail = fail!(options[:failure]) if options[:failure]
|
||||
@last_env = env
|
||||
return @fail if @fail
|
||||
raise "Request Phase"
|
||||
end
|
||||
def callback_phase
|
||||
@fail = fail!(options[:failure]) if options[:failure]
|
||||
@last_env = env
|
||||
puts @fail.inspect
|
||||
return @fail if @fail
|
||||
raise "Callback Phase"
|
||||
end
|
||||
end
|
||||
|
@ -64,6 +69,12 @@ describe OmniAuth::Strategy do
|
|||
strategy.last_env['rack.session']['omniauth.origin'].should == '/foo'
|
||||
end
|
||||
|
||||
it 'should be set on the failure env' do
|
||||
OmniAuth.config.should_receive(:on_failure).and_return(lambda{|env| env})
|
||||
@options = {:failure => :forced_fail}
|
||||
strategy.call(make_env('/auth/test/callback', 'rack.session' => {'omniauth.origin' => '/awesome'}))
|
||||
end
|
||||
|
||||
context "with script_name" do
|
||||
it 'should be set on the request phase, containing full path' do
|
||||
env = {'HTTP_REFERER' => 'http://example.com/sub_uri/origin', 'SCRIPT_NAME' => '/sub_uri' }
|
||||
|
|
Loading…
Reference in a new issue