Consider SCRIPT_NAME on omniauth url helper. Closes #876

This commit is contained in:
Vinicius Baggio 2011-02-25 14:20:12 -03:00
parent 392e664036
commit 305059f573
4 changed files with 22 additions and 2 deletions

View File

@ -17,6 +17,7 @@
* Do not depend on ActiveModel::Dirty
* Manual sign_in now triggers remember token
* Be sure to halt strategies on failures
* Consider SCRIPT_NAME on Omniauth paths
* deprecations
* Deprecated anybody_signed_in? in favor of signed_in? (by github.com/gavinhughes)

View File

@ -7,7 +7,11 @@ module Devise
class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1
def #{mapping.name}_omniauth_authorize_path(provider, params = {})
if Devise.omniauth_configs[provider.to_sym]
"/#{mapping.path}/auth/\#{provider}\#{'?'+params.to_param if params.present?}"
script_name = request.env["SCRIPT_NAME"]
path = "\#{script_name}/#{mapping.path}/auth/\#{provider}\".squeeze("/")
path << '?' + params.to_param if params.present?
path
else
raise ArgumentError, "Could not find omniauth provider \#{provider.inspect}"
end
@ -26,4 +30,4 @@ module Devise
end
end
end
end
end

View File

@ -111,6 +111,14 @@ class OmniauthableIntegrationTest < ActionController::IntegrationTest
end
end
test "generates a proper link when SCRIPT_NAME is set" do
header 'SCRIPT_NAME', '/q'
visit "/users/sign_in"
click_link "Sign in with Facebook"
assert '/q/users/auth/facebook', current_url
end
# The following two tests are commented because OmniAuth's test
# support is not yet able to support failure scenarios.
#

View File

@ -44,4 +44,11 @@ class OmniAuthRoutesTest < ActionController::TestCase
assert_equal "/users/auth/open_id",
@controller.omniauth_authorize_path(:user, :open_id)
end
test 'should set script name in the path if present' do
@request.env['SCRIPT_NAME'] = '/q'
assert_equal "/q/users/auth/facebook",
@controller.omniauth_authorize_path(:user, :facebook)
end
end