Consider SCRIPT_NAME on omniauth url helper. Closes #876
This commit is contained in:
parent
392e664036
commit
305059f573
|
@ -17,6 +17,7 @@
|
||||||
* Do not depend on ActiveModel::Dirty
|
* Do not depend on ActiveModel::Dirty
|
||||||
* Manual sign_in now triggers remember token
|
* Manual sign_in now triggers remember token
|
||||||
* Be sure to halt strategies on failures
|
* Be sure to halt strategies on failures
|
||||||
|
* Consider SCRIPT_NAME on Omniauth paths
|
||||||
|
|
||||||
* deprecations
|
* deprecations
|
||||||
* Deprecated anybody_signed_in? in favor of signed_in? (by github.com/gavinhughes)
|
* Deprecated anybody_signed_in? in favor of signed_in? (by github.com/gavinhughes)
|
||||||
|
|
|
@ -7,7 +7,11 @@ module Devise
|
||||||
class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1
|
class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1
|
||||||
def #{mapping.name}_omniauth_authorize_path(provider, params = {})
|
def #{mapping.name}_omniauth_authorize_path(provider, params = {})
|
||||||
if Devise.omniauth_configs[provider.to_sym]
|
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
|
else
|
||||||
raise ArgumentError, "Could not find omniauth provider \#{provider.inspect}"
|
raise ArgumentError, "Could not find omniauth provider \#{provider.inspect}"
|
||||||
end
|
end
|
||||||
|
@ -26,4 +30,4 @@ module Devise
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -111,6 +111,14 @@ class OmniauthableIntegrationTest < ActionController::IntegrationTest
|
||||||
end
|
end
|
||||||
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
|
# The following two tests are commented because OmniAuth's test
|
||||||
# support is not yet able to support failure scenarios.
|
# support is not yet able to support failure scenarios.
|
||||||
#
|
#
|
||||||
|
|
|
@ -44,4 +44,11 @@ class OmniAuthRoutesTest < ActionController::TestCase
|
||||||
assert_equal "/users/auth/open_id",
|
assert_equal "/users/auth/open_id",
|
||||||
@controller.omniauth_authorize_path(:user, :open_id)
|
@controller.omniauth_authorize_path(:user, :open_id)
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in New Issue