Skip to content

Commit

Permalink
Merge pull request #676 from watsonbox/master
Browse files Browse the repository at this point in the history
Dynamic Paths: Callback path not being correctly reported when custom callback path evaluator is truthy
  • Loading branch information
sferik committed Apr 17, 2013
2 parents fe14887 + effe836 commit deea8f2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/omniauth/strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,7 @@ def on_request_path?
end

def on_callback_path?
if options.callback_path.respond_to?(:call)
options.callback_path.call(env)
else
on_path?(callback_path)
end
on_path?(callback_path)
end

def on_path?(path)
Expand Down Expand Up @@ -382,7 +378,10 @@ def request_path
end

def callback_path
options[:callback_path].is_a?(String) ? options[:callback_path] : (custom_path(:request_path) || "#{path_prefix}/#{name}/callback")
path = options[:callback_path] if options[:callback_path].is_a?(String)
path ||= current_path if options[:callback_path].respond_to?(:call) && options[:callback_path].call(env)
path ||= custom_path(:request_path)
path ||= "#{path_prefix}/#{name}/callback"
end

def setup_path
Expand Down
9 changes: 9 additions & 0 deletions spec/omniauth/strategy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,15 @@ def make_env(path = '/auth/test', props = {})
strategy_instance = fresh_strategy.new(nil, :request_path => lambda{|env| "/auth/boo/callback/22" })
expect(strategy_instance.callback_path).to eq('/auth/boo/callback/22')
end

it "correctly reports the callback path when the custom callback path evaluator is truthy" do
strategy_instance = ExampleStrategy.new(app,
:callback_path => lambda{|env| env['PATH_INFO'] == "/auth/bish/bosh/callback"}
)

expect{strategy_instance.call(make_env('/auth/bish/bosh/callback')) }.to raise_error("Callback Phase")
expect(strategy_instance.callback_path).to eq('/auth/bish/bosh/callback')
end
end

context "custom paths" do
Expand Down

0 comments on commit deea8f2

Please sign in to comment.