diff --git a/app/controllers/devise/omniauth_callbacks_controller.rb b/app/controllers/devise/omniauth_callbacks_controller.rb index 30aa3f0a..d440020d 100644 --- a/app/controllers/devise/omniauth_callbacks_controller.rb +++ b/app/controllers/devise/omniauth_callbacks_controller.rb @@ -1,6 +1,10 @@ class Devise::OmniauthCallbacksController < DeviseController prepend_before_filter { request.env["devise.skip_timeout"] = true } + def passthru + render :status => 404, :text => "Not found. Authentication passthru." + end + def failure set_flash_message :alert, :failure, :kind => failed_strategy.name.to_s.humanize, :reason => failure_message redirect_to after_omniauth_failure_path_for(resource_name) diff --git a/lib/devise/omniauth/url_helpers.rb b/lib/devise/omniauth/url_helpers.rb index 58cc1392..d7b3a36e 100644 --- a/lib/devise/omniauth/url_helpers.rb +++ b/lib/devise/omniauth/url_helpers.rb @@ -2,21 +2,6 @@ module Devise module OmniAuth module UrlHelpers def self.define_helpers(mapping) - return unless mapping.omniauthable? - - class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1 - def #{mapping.name}_omniauth_authorize_path(provider, params = {}) - if Devise.omniauth_configs[provider.to_sym] - 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 - end - URL_HELPERS end def omniauth_authorize_path(resource_or_scope, *args) diff --git a/lib/devise/rails/routes.rb b/lib/devise/rails/routes.rb index df623ac8..8fb5a3b0 100644 --- a/lib/devise/rails/routes.rb +++ b/lib/devise/rails/routes.rb @@ -396,8 +396,17 @@ module ActionDispatch::Routing path_prefix = Devise.omniauth_path_prefix || "/#{mapping.path}/auth".squeeze("/") set_omniauth_path_prefix!(path_prefix) - match "#{path_prefix}/:action/callback", :constraints => { :action => Regexp.union(mapping.to.omniauth_providers.map(&:to_s)) }, - :to => controllers[:omniauth_callbacks], :as => :omniauth_callback + providers = Regexp.union(mapping.to.omniauth_providers.map(&:to_s)) + + match "#{path_prefix}/:provider", + :constraints => { :provider => providers }, + :to => "#{controllers[:omniauth_callbacks]}#passthru", + :as => :omniauth_authorize + + match "#{path_prefix}/:action/callback", + :constraints => { :action => providers }, + :to => controllers[:omniauth_callbacks], + :as => :omniauth_callback ensure @scope[:path] = path end diff --git a/test/omniauth/url_helpers_test.rb b/test/omniauth/url_helpers_test.rb index be8541b3..67054b65 100644 --- a/test/omniauth/url_helpers_test.rb +++ b/test/omniauth/url_helpers_test.rb @@ -30,7 +30,7 @@ class OmniAuthRoutesTest < ActionController::TestCase test 'should generate authorization path' do assert_match "/users/auth/facebook", @controller.omniauth_authorize_path(:user, :facebook) - assert_raise ArgumentError do + assert_raise ActionController::RoutingError do @controller.omniauth_authorize_path(:user, :github) end end @@ -48,11 +48,4 @@ class OmniAuthRoutesTest < ActionController::TestCase assert_equal "/users/auth/openid", @controller.omniauth_authorize_path(:user, :openid) 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