2011-09-03 18:08:07 +00:00
|
|
|
module OmniAuth
|
|
|
|
class Builder < ::Rack::Builder
|
2012-01-17 20:57:54 +00:00
|
|
|
def initialize(app, &block)
|
2013-01-10 17:13:52 +00:00
|
|
|
@options = nil
|
2015-08-20 23:46:02 +00:00
|
|
|
if rack14? || rack2?
|
2012-01-17 20:57:54 +00:00
|
|
|
super
|
|
|
|
else
|
|
|
|
@app = app
|
|
|
|
super(&block)
|
2012-05-29 17:59:10 +00:00
|
|
|
@ins << @app
|
2012-01-17 20:57:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def rack14?
|
|
|
|
Rack.release.split('.')[1].to_i >= 4
|
|
|
|
end
|
|
|
|
|
2015-08-20 23:46:02 +00:00
|
|
|
def rack2?
|
|
|
|
Rack.release.start_with? '2.'
|
|
|
|
end
|
|
|
|
|
2011-09-03 18:08:07 +00:00
|
|
|
def on_failure(&block)
|
|
|
|
OmniAuth.config.on_failure = block
|
|
|
|
end
|
|
|
|
|
2013-09-03 15:16:18 +00:00
|
|
|
def before_options_phase(&block)
|
|
|
|
OmniAuth.config.before_options_phase = block
|
2013-02-25 23:52:36 +00:00
|
|
|
end
|
|
|
|
|
2013-09-03 15:16:18 +00:00
|
|
|
def before_request_phase(&block)
|
|
|
|
OmniAuth.config.before_request_phase = block
|
2013-02-25 23:52:36 +00:00
|
|
|
end
|
|
|
|
|
2013-09-03 15:16:18 +00:00
|
|
|
def before_callback_phase(&block)
|
|
|
|
OmniAuth.config.before_callback_phase = block
|
2013-02-25 23:52:36 +00:00
|
|
|
end
|
|
|
|
|
2011-09-03 18:08:07 +00:00
|
|
|
def configure(&block)
|
|
|
|
OmniAuth.configure(&block)
|
|
|
|
end
|
|
|
|
|
2012-04-12 21:01:48 +00:00
|
|
|
def options(options = false)
|
|
|
|
return @options || {} if options == false
|
|
|
|
@options = options
|
|
|
|
end
|
|
|
|
|
2011-09-03 18:08:07 +00:00
|
|
|
def provider(klass, *args, &block)
|
|
|
|
if klass.is_a?(Class)
|
|
|
|
middleware = klass
|
|
|
|
else
|
2011-11-25 14:03:23 +00:00
|
|
|
begin
|
|
|
|
middleware = OmniAuth::Strategies.const_get("#{OmniAuth::Utils.camelize(klass.to_s)}")
|
|
|
|
rescue NameError
|
2014-01-25 11:19:24 +00:00
|
|
|
raise(LoadError.new("Could not find matching strategy for #{klass.inspect}. You may need to install an additional gem (such as omniauth-#{klass})."))
|
2011-11-25 14:03:23 +00:00
|
|
|
end
|
2011-09-03 18:08:07 +00:00
|
|
|
end
|
|
|
|
|
2012-04-12 21:01:48 +00:00
|
|
|
args.last.is_a?(Hash) ? args.push(options.merge(args.pop)) : args.push(options)
|
2011-09-03 18:08:07 +00:00
|
|
|
use middleware, *args, &block
|
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
|
|
|
to_app.call(env)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|