Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Delegate omniauth_authorize_path to the router, closes #1843

  • Loading branch information...
commit b1633f2454cd1f679ba82330ee2af6a70791fd09 1 parent 41a9118
@josevalim josevalim authored
View
4 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)
View
15 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)
View
13 lib/devise/rails/routes.rb
@@ -396,8 +396,17 @@ def devise_omniauth_callback(mapping, controllers) #:nodoc:
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
View
9 test/omniauth/url_helpers_test.rb
@@ -30,7 +30,7 @@ def assert_path(action, provider, with_param=true)
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 @@ def assert_path(action, provider, with_param=true)
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

0 comments on commit b1633f2

Please sign in to comment.
Something went wrong with that request. Please try again.