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
|
response
|
||||||
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
|
||||||
elsif current_path == callback_path
|
elsif current_path == callback_path
|
||||||
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'] == ''
|
||||||
|
|
||||||
callback_phase
|
callback_phase
|
||||||
else
|
else
|
||||||
|
@ -62,9 +62,9 @@ module OmniAuth
|
||||||
response
|
response
|
||||||
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
|
||||||
redirect(callback_path)
|
redirect(callback_path)
|
||||||
end
|
end
|
||||||
|
@ -74,8 +74,8 @@ module OmniAuth
|
||||||
fail!(mocked_auth)
|
fail!(mocked_auth)
|
||||||
else
|
else
|
||||||
@env['omniauth.auth'] = mocked_auth
|
@env['omniauth.auth'] = mocked_auth
|
||||||
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'] == ''
|
||||||
call_app!
|
call_app!
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
@ -192,7 +192,7 @@ module OmniAuth
|
||||||
self.env['omniauth.error'] = exception
|
self.env['omniauth.error'] = exception
|
||||||
self.env['omniauth.error.type'] = message_key.to_sym
|
self.env['omniauth.error.type'] = message_key.to_sym
|
||||||
self.env['omniauth.error.strategy'] = self
|
self.env['omniauth.error.strategy'] = self
|
||||||
|
|
||||||
OmniAuth.config.on_failure.call(self.env)
|
OmniAuth.config.on_failure.call(self.env)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,11 +5,16 @@ class ExampleStrategy
|
||||||
def call(env); self.call!(env) end
|
def call(env); self.call!(env) end
|
||||||
attr_reader :last_env
|
attr_reader :last_env
|
||||||
def request_phase
|
def request_phase
|
||||||
@last_env = env
|
@fail = fail!(options[:failure]) if options[:failure]
|
||||||
|
@last_env = env
|
||||||
|
return @fail if @fail
|
||||||
raise "Request Phase"
|
raise "Request Phase"
|
||||||
end
|
end
|
||||||
def callback_phase
|
def callback_phase
|
||||||
|
@fail = fail!(options[:failure]) if options[:failure]
|
||||||
@last_env = env
|
@last_env = env
|
||||||
|
puts @fail.inspect
|
||||||
|
return @fail if @fail
|
||||||
raise "Callback Phase"
|
raise "Callback Phase"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -64,6 +69,12 @@ describe OmniAuth::Strategy do
|
||||||
strategy.last_env['rack.session']['omniauth.origin'].should == '/foo'
|
strategy.last_env['rack.session']['omniauth.origin'].should == '/foo'
|
||||||
end
|
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
|
context "with script_name" do
|
||||||
it 'should be set on the request phase, containing full path' 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' }
|
env = {'HTTP_REFERER' => 'http://example.com/sub_uri/origin', 'SCRIPT_NAME' => '/sub_uri' }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue