1
0
Fork 0
mirror of https://github.com/omniauth/omniauth.git synced 2022-11-09 12:31:49 -05:00

Set omniauth.origin when invoking callbacks in testmode.

This commit is contained in:
Paul Jones 2011-03-12 08:32:16 +00:00
parent dc44c54d80
commit 7b3644fd62
2 changed files with 24 additions and 1 deletions

View file

@ -61,7 +61,11 @@ module OmniAuth
if response = call_through_to_app
response
else
if 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']
end
redirect(callback_path)
end
elsif current_path == callback_path
@ -70,6 +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'] == ''
call_app!
end
else

View file

@ -260,6 +260,23 @@ describe OmniAuth::Strategy do
strategy.call make_env('/auth/test/callback')
strategy.env['omniauth.error.type'].should == :invalid_credentials
end
it 'should set omniauth.origin on the request phase' do
strategy.call(make_env('/auth/test', 'HTTP_REFERER' => 'http://example.com/origin'))
strategy.env['rack.session']['omniauth.origin'].should == 'http://example.com/origin'
end
it 'should set omniauth.origin from the params if provided' do
strategy.call(make_env('/auth/test', 'QUERY_STRING' => 'origin=/foo'))
strategy.env['rack.session']['omniauth.origin'].should == '/foo'
end
it 'should turn omniauth.origin into an env variable on the callback phase' do
OmniAuth.config.mock_auth[:test] = {}
strategy.call(make_env('/auth/test/callback', 'rack.session' => {'omniauth.origin' => 'http://example.com/origin'}))
strategy.env['omniauth.origin'].should == 'http://example.com/origin'
end
end
context 'custom full_host' do