diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 63e30607..02c8f2ed 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -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) diff --git a/lib/devise/omniauth/url_helpers.rb b/lib/devise/omniauth/url_helpers.rb index d7ab110a..58cc1392 100644 --- a/lib/devise/omniauth/url_helpers.rb +++ b/lib/devise/omniauth/url_helpers.rb @@ -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 \ No newline at end of file +end diff --git a/test/integration/omniauthable_test.rb b/test/integration/omniauthable_test.rb index 8f92c919..5ac35e8c 100644 --- a/test/integration/omniauthable_test.rb +++ b/test/integration/omniauthable_test.rb @@ -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. # diff --git a/test/omniauth/url_helpers_test.rb b/test/omniauth/url_helpers_test.rb index ad98ca50..88894696 100644 --- a/test/omniauth/url_helpers_test.rb +++ b/test/omniauth/url_helpers_test.rb @@ -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