Adds dynamic path evaluation options. Closes #585
This commit is contained in:
parent
ab3d87ce58
commit
a682ba1f6d
|
@ -226,12 +226,20 @@ module OmniAuth
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_request_path?
|
def on_request_path?
|
||||||
|
if options.request_path.respond_to?(:call)
|
||||||
|
options.request_path.call(env)
|
||||||
|
else
|
||||||
on_path?(request_path)
|
on_path?(request_path)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def on_callback_path?
|
def on_callback_path?
|
||||||
|
if options.callback_path.respond_to?(:call)
|
||||||
|
options.callback_path.call(env)
|
||||||
|
else
|
||||||
on_path?(callback_path)
|
on_path?(callback_path)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def on_path?(path)
|
def on_path?(path)
|
||||||
current_path.casecmp(path) == 0
|
current_path.casecmp(path) == 0
|
||||||
|
@ -350,12 +358,22 @@ module OmniAuth
|
||||||
options[:path_prefix] || OmniAuth.config.path_prefix
|
options[:path_prefix] || OmniAuth.config.path_prefix
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def custom_path(kind)
|
||||||
|
if options[kind].respond_to?(:call)
|
||||||
|
result = options[kind].call(env)
|
||||||
|
return nil unless result.is_a?(String)
|
||||||
|
result
|
||||||
|
else
|
||||||
|
options[kind]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def request_path
|
def request_path
|
||||||
options[:request_path] || "#{path_prefix}/#{name}"
|
options[:request_path].is_a?(String) ? options[:request_path] : "#{path_prefix}/#{name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def callback_path
|
def callback_path
|
||||||
options[:callback_path] || "#{path_prefix}/#{name}/callback"
|
options[:callback_path].is_a?(String) ? options[:callback_path] : (custom_path(:request_path) || "#{path_prefix}/#{name}/callback")
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup_path
|
def setup_path
|
||||||
|
|
|
@ -346,6 +346,23 @@ describe OmniAuth::Strategy do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'dynamic paths' do
|
||||||
|
it 'should run the request phase if the custom request path evaluator is truthy' do
|
||||||
|
@options = {:request_path => lambda{|env| true}}
|
||||||
|
lambda{ strategy.call(make_env('/asoufibasfi')) }.should raise_error("Request Phase")
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should run the callback phase if the custom callback path evaluator is truthy' do
|
||||||
|
@options = {:callback_path => lambda{|env| true}}
|
||||||
|
lambda{ strategy.call(make_env('/asoufiasod')) }.should raise_error("Callback Phase")
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should provide a custom callback path if request_path evals to a string' do
|
||||||
|
strategy_instance = fresh_strategy.new(nil, :request_path => lambda{|env| "/auth/boo/callback/22" })
|
||||||
|
strategy_instance.callback_path.should == '/auth/boo/callback/22'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'custom paths' do
|
context 'custom paths' do
|
||||||
it 'should use a custom request_path if one is provided' do
|
it 'should use a custom request_path if one is provided' do
|
||||||
@options = {:request_path => '/awesome'}
|
@options = {:request_path => '/awesome'}
|
||||||
|
|
Loading…
Reference in New Issue