Ensure hook names are descriptive enough.
before_options_phase before_request_phase before_callback_phase
This commit is contained in:
parent
a239ba2980
commit
74bcbd7122
|
@ -34,9 +34,9 @@ module OmniAuth
|
||||||
:path_prefix => '/auth',
|
:path_prefix => '/auth',
|
||||||
:on_failure => OmniAuth::FailureEndpoint,
|
:on_failure => OmniAuth::FailureEndpoint,
|
||||||
:failure_raise_out_environments => ['development'],
|
:failure_raise_out_environments => ['development'],
|
||||||
:on_callback_hook => nil,
|
:before_request_phase => nil,
|
||||||
:on_options_hook => nil,
|
:before_callback_phase => nil,
|
||||||
:on_request_hook => nil,
|
:before_options_phase => nil,
|
||||||
:form_css => Form::DEFAULT_CSS,
|
:form_css => Form::DEFAULT_CSS,
|
||||||
:test_mode => false,
|
:test_mode => false,
|
||||||
:logger => default_logger,
|
:logger => default_logger,
|
||||||
|
@ -68,31 +68,30 @@ module OmniAuth
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_callback_hook(&block)
|
def before_callback_phase(&block)
|
||||||
if block_given?
|
if block_given?
|
||||||
@on_callback_hook = block
|
@before_callback_phase = block
|
||||||
else
|
else
|
||||||
@on_callback_hook
|
@before_callback_phase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_options_hook(&block)
|
def before_options_phase(&block)
|
||||||
if block_given?
|
if block_given?
|
||||||
@on_options_hook = block
|
@before_options_phase = block
|
||||||
else
|
else
|
||||||
@on_options_hook
|
@before_options_phase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_request_hook(&block)
|
def before_request_phase(&block)
|
||||||
if block_given?
|
if block_given?
|
||||||
@on_request_hook = block
|
@before_request_phase = block
|
||||||
else
|
else
|
||||||
@on_request_hook
|
@before_request_phase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def add_mock(provider, mock={})
|
def add_mock(provider, mock={})
|
||||||
# Stringify keys recursively one level.
|
# Stringify keys recursively one level.
|
||||||
mock.keys.each do |key|
|
mock.keys.each do |key|
|
||||||
|
@ -124,7 +123,7 @@ module OmniAuth
|
||||||
self.camelizations[name.to_s] = camelized.to_s
|
self.camelizations[name.to_s] = camelized.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_writer :on_failure, :on_callback_hook,:on_options_hook,:on_request_hook
|
attr_writer :on_failure, :before_callback_phase, :before_options_phase, :before_request_phase
|
||||||
attr_accessor :failure_raise_out_environments, :path_prefix, :allowed_request_methods, :form_css, :test_mode, :mock_auth, :full_host, :camelizations, :logger
|
attr_accessor :failure_raise_out_environments, :path_prefix, :allowed_request_methods, :form_css, :test_mode, :mock_auth, :full_host, :camelizations, :logger
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -186,7 +186,7 @@ module OmniAuth
|
||||||
|
|
||||||
# Responds to an OPTIONS request.
|
# Responds to an OPTIONS request.
|
||||||
def options_call
|
def options_call
|
||||||
OmniAuth.config.on_options_hook.call(self.env) if OmniAuth.config.on_options_hook
|
OmniAuth.config.before_options_phase.call(self.env) if OmniAuth.config.before_options_phase
|
||||||
verbs = OmniAuth.config.allowed_request_methods.map(&:to_s).map(&:upcase).join(', ')
|
verbs = OmniAuth.config.allowed_request_methods.map(&:to_s).map(&:upcase).join(', ')
|
||||||
return [ 200, { 'Allow' => verbs }, [] ]
|
return [ 200, { 'Allow' => verbs }, [] ]
|
||||||
end
|
end
|
||||||
|
@ -200,7 +200,7 @@ module OmniAuth
|
||||||
#store query params from the request url, extracted in the callback_phase
|
#store query params from the request url, extracted in the callback_phase
|
||||||
session['omniauth.params'] = request.params
|
session['omniauth.params'] = request.params
|
||||||
|
|
||||||
OmniAuth.config.on_request_hook.call(self.env) if OmniAuth.config.on_request_hook
|
OmniAuth.config.before_request_phase.call(self.env) if OmniAuth.config.before_request_phase
|
||||||
|
|
||||||
if options.form.respond_to?(:call)
|
if options.form.respond_to?(:call)
|
||||||
log :info, "Rendering form from supplied Rack endpoint."
|
log :info, "Rendering form from supplied Rack endpoint."
|
||||||
|
@ -225,7 +225,7 @@ module OmniAuth
|
||||||
@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'] == ''
|
||||||
@env['omniauth.params'] = session.delete('omniauth.params') || {}
|
@env['omniauth.params'] = session.delete('omniauth.params') || {}
|
||||||
OmniAuth.config.on_callback_hook.call(@env) if OmniAuth.config.on_callback_hook
|
OmniAuth.config.before_callback_phase.call(@env) if OmniAuth.config.before_callback_phase
|
||||||
callback_phase
|
callback_phase
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -268,7 +268,7 @@ module OmniAuth
|
||||||
setup_phase
|
setup_phase
|
||||||
|
|
||||||
session['omniauth.params'] = request.params
|
session['omniauth.params'] = request.params
|
||||||
OmniAuth.config.on_request_hook.call(self.env) if OmniAuth.config.on_request_hook
|
OmniAuth.config.before_request_phase.call(self.env) if OmniAuth.config.before_request_phase
|
||||||
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}$/)
|
||||||
|
@ -287,7 +287,7 @@ module OmniAuth
|
||||||
@env['omniauth.params'] = session.delete('omniauth.params') || {}
|
@env['omniauth.params'] = session.delete('omniauth.params') || {}
|
||||||
@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'] == ''
|
||||||
OmniAuth.config.on_callback_hook.call(@env) if OmniAuth.config.on_callback_hook
|
OmniAuth.config.before_callback_phase.call(@env) if OmniAuth.config.before_callback_phase
|
||||||
call_app!
|
call_app!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -596,9 +596,9 @@ describe OmniAuth::Strategy do
|
||||||
expect(strategy.env['omniauth.origin']).to eq('http://example.com/origin')
|
expect(strategy.env['omniauth.origin']).to eq('http://example.com/origin')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "executes callback_hook on the callback phase" do
|
it "executes callback hook on the callback phase" do
|
||||||
OmniAuth.config.mock_auth[:test] = {}
|
OmniAuth.config.mock_auth[:test] = {}
|
||||||
OmniAuth.config.on_callback_hook do |env|
|
OmniAuth.config.before_callback_phase do |env|
|
||||||
env['foobar']='baz'
|
env['foobar']='baz'
|
||||||
end
|
end
|
||||||
strategy.call(make_env('/auth/test/callback', 'rack.session' => {'omniauth.origin' => 'http://example.com/origin'}))
|
strategy.call(make_env('/auth/test/callback', 'rack.session' => {'omniauth.origin' => 'http://example.com/origin'}))
|
||||||
|
@ -612,9 +612,9 @@ describe OmniAuth::Strategy do
|
||||||
expect(strategy.env['rack.session']['omniauth.params']).to eq({'foo' => 'bar'})
|
expect(strategy.env['rack.session']['omniauth.params']).to eq({'foo' => 'bar'})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "executes request_hook on the request phase" do
|
it "executes request hook on the request phase" do
|
||||||
OmniAuth.config.mock_auth[:test] = {}
|
OmniAuth.config.mock_auth[:test] = {}
|
||||||
OmniAuth.config.on_request_hook do |env|
|
OmniAuth.config.before_request_phase do |env|
|
||||||
env['foobar']='baz'
|
env['foobar']='baz'
|
||||||
end
|
end
|
||||||
strategy.call(make_env('/auth/test', 'QUERY_STRING' => 'foo=bar'))
|
strategy.call(make_env('/auth/test', 'QUERY_STRING' => 'foo=bar'))
|
||||||
|
|
|
@ -26,20 +26,20 @@ describe OmniAuth do
|
||||||
end
|
end
|
||||||
|
|
||||||
before do
|
before do
|
||||||
@old_path_prefix = OmniAuth.config.path_prefix
|
@old_path_prefix = OmniAuth.config.path_prefix
|
||||||
@old_on_failure = OmniAuth.config.on_failure
|
@old_on_failure = OmniAuth.config.on_failure
|
||||||
@old_on_callback_hook = OmniAuth.config.on_callback_hook
|
@old_before_callback_phase = OmniAuth.config.before_callback_phase
|
||||||
@old_on_options_hook = OmniAuth.config.on_options_hook
|
@old_before_options_phase = OmniAuth.config.before_options_phase
|
||||||
@old_on_request_hook = OmniAuth.config.on_request_hook
|
@old_before_request_phase = OmniAuth.config.before_request_phase
|
||||||
end
|
end
|
||||||
|
|
||||||
after do
|
after do
|
||||||
OmniAuth.configure do |config|
|
OmniAuth.configure do |config|
|
||||||
config.path_prefix = @old_path_prefix
|
config.path_prefix = @old_path_prefix
|
||||||
config.on_failure = @old_on_failure
|
config.on_failure = @old_on_failure
|
||||||
config.on_callback_hook = @old_on_callback_hook
|
config.before_callback_phase = @old_before_callback_phase
|
||||||
config.on_options_hook = @old_on_options_hook
|
config.before_options_phase = @old_before_options_phase
|
||||||
config.on_request_hook = @old_on_request_hook
|
config.before_request_phase = @old_before_request_phase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -63,29 +63,29 @@ describe OmniAuth do
|
||||||
|
|
||||||
it "is able to set hook on option_call" do
|
it "is able to set hook on option_call" do
|
||||||
OmniAuth.configure do |config|
|
OmniAuth.configure do |config|
|
||||||
config.on_options_hook do
|
config.before_options_phase do
|
||||||
'yoyo'
|
'yoyo'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
expect(OmniAuth.config.on_options_hook.call).to eq('yoyo')
|
expect(OmniAuth.config.before_options_phase.call).to eq('yoyo')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "is able to set hook on request_call" do
|
it "is able to set hook on request_call" do
|
||||||
OmniAuth.configure do |config|
|
OmniAuth.configure do |config|
|
||||||
config.on_request_hook do
|
config.before_request_phase do
|
||||||
'heyhey'
|
'heyhey'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
expect(OmniAuth.config.on_request_hook.call).to eq('heyhey')
|
expect(OmniAuth.config.before_request_phase.call).to eq('heyhey')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "is able to set hook on callback_call" do
|
it "is able to set hook on callback_call" do
|
||||||
OmniAuth.configure do |config|
|
OmniAuth.configure do |config|
|
||||||
config.on_callback_hook do
|
config.before_callback_phase do
|
||||||
'heyhey'
|
'heyhey'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
expect(OmniAuth.config.on_callback_hook.call).to eq('heyhey')
|
expect(OmniAuth.config.before_callback_phase.call).to eq('heyhey')
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "mock auth" do
|
describe "mock auth" do
|
||||||
|
|
Loading…
Reference in New Issue