mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Delegate omniauth_authorize_path to the router, closes #1843
This commit is contained in:
parent
41a91188f5
commit
b1633f2454
4 changed files with 16 additions and 25 deletions
|
@ -1,6 +1,10 @@
|
||||||
class Devise::OmniauthCallbacksController < DeviseController
|
class Devise::OmniauthCallbacksController < DeviseController
|
||||||
prepend_before_filter { request.env["devise.skip_timeout"] = true }
|
prepend_before_filter { request.env["devise.skip_timeout"] = true }
|
||||||
|
|
||||||
|
def passthru
|
||||||
|
render :status => 404, :text => "Not found. Authentication passthru."
|
||||||
|
end
|
||||||
|
|
||||||
def failure
|
def failure
|
||||||
set_flash_message :alert, :failure, :kind => failed_strategy.name.to_s.humanize, :reason => failure_message
|
set_flash_message :alert, :failure, :kind => failed_strategy.name.to_s.humanize, :reason => failure_message
|
||||||
redirect_to after_omniauth_failure_path_for(resource_name)
|
redirect_to after_omniauth_failure_path_for(resource_name)
|
||||||
|
|
|
@ -2,21 +2,6 @@ module Devise
|
||||||
module OmniAuth
|
module OmniAuth
|
||||||
module UrlHelpers
|
module UrlHelpers
|
||||||
def self.define_helpers(mapping)
|
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
|
end
|
||||||
|
|
||||||
def omniauth_authorize_path(resource_or_scope, *args)
|
def omniauth_authorize_path(resource_or_scope, *args)
|
||||||
|
|
|
@ -396,8 +396,17 @@ module ActionDispatch::Routing
|
||||||
path_prefix = Devise.omniauth_path_prefix || "/#{mapping.path}/auth".squeeze("/")
|
path_prefix = Devise.omniauth_path_prefix || "/#{mapping.path}/auth".squeeze("/")
|
||||||
set_omniauth_path_prefix!(path_prefix)
|
set_omniauth_path_prefix!(path_prefix)
|
||||||
|
|
||||||
match "#{path_prefix}/:action/callback", :constraints => { :action => Regexp.union(mapping.to.omniauth_providers.map(&:to_s)) },
|
providers = Regexp.union(mapping.to.omniauth_providers.map(&:to_s))
|
||||||
:to => controllers[:omniauth_callbacks], :as => :omniauth_callback
|
|
||||||
|
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
|
ensure
|
||||||
@scope[:path] = path
|
@scope[:path] = path
|
||||||
end
|
end
|
||||||
|
|
|
@ -30,7 +30,7 @@ class OmniAuthRoutesTest < ActionController::TestCase
|
||||||
test 'should generate authorization path' do
|
test 'should generate authorization path' do
|
||||||
assert_match "/users/auth/facebook", @controller.omniauth_authorize_path(:user, :facebook)
|
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)
|
@controller.omniauth_authorize_path(:user, :github)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -48,11 +48,4 @@ class OmniAuthRoutesTest < ActionController::TestCase
|
||||||
assert_equal "/users/auth/openid",
|
assert_equal "/users/auth/openid",
|
||||||
@controller.omniauth_authorize_path(:user, :openid)
|
@controller.omniauth_authorize_path(:user, :openid)
|
||||||
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 a new issue