Permalink
Browse files

Consider SCRIPT_NAME on omniauth url helper. Closes #876

  • Loading branch information...
1 parent 392e664 commit 305059f57379f9aced807e3e057231f4a20e9de7 @vinibaggio vinibaggio committed Feb 25, 2011
View
@@ -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)
@@ -7,7 +7,11 @@ def self.define_helpers(mapping)
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 @@ def omniauth_callback_path(resource_or_scope, *args)
end
end
end
-end
+end
@@ -111,6 +111,14 @@ def stub_action!(name)
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.
#
@@ -44,4 +44,11 @@ def assert_path(action, provider, with_param=true)
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

0 comments on commit 305059f

Please sign in to comment.