From 5fbc41943d9ef4b4f0372d1ca14da438d2d3712b Mon Sep 17 00:00:00 2001 From: Michael Bleigh Date: Mon, 5 Mar 2012 20:27:08 -0500 Subject: [PATCH] Extract default on_failure into class. References #578. --- lib/omniauth.rb | 7 ++----- lib/omniauth/failure_endpoint.rb | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 lib/omniauth/failure_endpoint.rb diff --git a/lib/omniauth.rb b/lib/omniauth.rb index 10b0aaf..b4bf44d 100644 --- a/lib/omniauth.rb +++ b/lib/omniauth.rb @@ -11,6 +11,7 @@ module OmniAuth autoload :Test, 'omniauth/test' autoload :Form, 'omniauth/form' autoload :AuthHash, 'omniauth/auth_hash' + autoload :FailureEndpoint, 'omniauth/failure_endpoint' def self.strategies @@strategies ||= [] @@ -22,11 +23,7 @@ module OmniAuth @@defaults = { :camelizations => {}, :path_prefix => '/auth', - :on_failure => Proc.new do |env| - message_key = env['omniauth.error.type'] - new_path = "#{env['SCRIPT_NAME']}#{OmniAuth.config.path_prefix}/failure?message=#{message_key}" - [302, {'Location' => new_path, 'Content-Type'=> 'text/html'}, []] - end, + :on_failure => OmniAuth::FailureEndpoint, :form_css => Form::DEFAULT_CSS, :test_mode => false, :allowed_request_methods => [:get, :post], diff --git a/lib/omniauth/failure_endpoint.rb b/lib/omniauth/failure_endpoint.rb new file mode 100644 index 0000000..c30116f --- /dev/null +++ b/lib/omniauth/failure_endpoint.rb @@ -0,0 +1,19 @@ +module OmniAuth + class FailureEndpoint + attr_reader :env + + def self.call(env) + new(env).call + end + + def initialize(env) + @env = env + end + + def call + message_key = env['omniauth.error.type'] + new_path = "#{env['SCRIPT_NAME']}#{OmniAuth.config.path_prefix}/failure?message=#{message_key}" + [302, {'Location' => new_path, 'Content-Type'=> 'text/html'}, []] + end + end +end \ No newline at end of file