From 99e565817620c46c8dd5ce7f7279a98ead6b4e94 Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Wed, 14 Jan 2015 15:33:07 +0000 Subject: [PATCH 1/2] exit early if no auth request don't re-evaluate available providers for requests that are certainly no authentication requests (such as resources) --- lib/omniauth/flexible_strategy.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/omniauth/flexible_strategy.rb b/lib/omniauth/flexible_strategy.rb index ee37b52d3f..52b085fde4 100644 --- a/lib/omniauth/flexible_strategy.rb +++ b/lib/omniauth/flexible_strategy.rb @@ -40,7 +40,7 @@ module OmniAuth module FlexibleStrategy def on_auth_path? - (match_provider! || false) && super + !not_on_auth_path? && (match_provider! || false) && super end ## @@ -72,6 +72,14 @@ module OmniAuth "#{path_prefix}/#{name}" end + ## + # This method returning false does not mean that the current request should be handled by + # this strategy. The method can, however, indicate that a request should NOT be handled by it. + # In which case it returns true. + def not_on_auth_path? + (current_path =~ /#{path_prefix}/) != 0 + end + def providers @providers ||= OpenProject::Plugins::AuthPlugin.providers_for(self.class) end From 787064aab2e60e17dcb06d2126c0aaaa8fc09dfa Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Wed, 14 Jan 2015 16:43:03 +0000 Subject: [PATCH 2/2] needs less double negative --- lib/omniauth/flexible_strategy.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/omniauth/flexible_strategy.rb b/lib/omniauth/flexible_strategy.rb index 52b085fde4..105599d93f 100644 --- a/lib/omniauth/flexible_strategy.rb +++ b/lib/omniauth/flexible_strategy.rb @@ -40,7 +40,7 @@ module OmniAuth module FlexibleStrategy def on_auth_path? - !not_on_auth_path? && (match_provider! || false) && super + possible_auth_path? && (match_provider! || false) && super end ## @@ -73,11 +73,10 @@ module OmniAuth end ## - # This method returning false does not mean that the current request should be handled by - # this strategy. The method can, however, indicate that a request should NOT be handled by it. - # In which case it returns true. - def not_on_auth_path? - (current_path =~ /#{path_prefix}/) != 0 + # Returns true if the current path could be an authentication request, + # false otherwise (e.g. for resources). + def possible_auth_path? + current_path =~ /\A#{path_prefix}/ end def providers