Extract default on_failure into class. References #578.
This commit is contained in:
parent
ef29d52c57
commit
5fbc41943d
|
@ -11,6 +11,7 @@ module OmniAuth
|
||||||
autoload :Test, 'omniauth/test'
|
autoload :Test, 'omniauth/test'
|
||||||
autoload :Form, 'omniauth/form'
|
autoload :Form, 'omniauth/form'
|
||||||
autoload :AuthHash, 'omniauth/auth_hash'
|
autoload :AuthHash, 'omniauth/auth_hash'
|
||||||
|
autoload :FailureEndpoint, 'omniauth/failure_endpoint'
|
||||||
|
|
||||||
def self.strategies
|
def self.strategies
|
||||||
@@strategies ||= []
|
@@strategies ||= []
|
||||||
|
@ -22,11 +23,7 @@ module OmniAuth
|
||||||
@@defaults = {
|
@@defaults = {
|
||||||
:camelizations => {},
|
:camelizations => {},
|
||||||
:path_prefix => '/auth',
|
:path_prefix => '/auth',
|
||||||
:on_failure => Proc.new do |env|
|
:on_failure => OmniAuth::FailureEndpoint,
|
||||||
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,
|
|
||||||
:form_css => Form::DEFAULT_CSS,
|
:form_css => Form::DEFAULT_CSS,
|
||||||
:test_mode => false,
|
:test_mode => false,
|
||||||
:allowed_request_methods => [:get, :post],
|
:allowed_request_methods => [:get, :post],
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue