2011-09-03 14:08:07 -04:00
|
|
|
module OmniAuth
|
|
|
|
class Builder < ::Rack::Builder
|
|
|
|
def on_failure(&block)
|
|
|
|
OmniAuth.config.on_failure = block
|
|
|
|
end
|
|
|
|
|
2013-09-03 11:16:18 -04:00
|
|
|
def before_options_phase(&block)
|
|
|
|
OmniAuth.config.before_options_phase = block
|
2013-02-25 18:52:36 -05:00
|
|
|
end
|
|
|
|
|
2013-09-03 11:16:18 -04:00
|
|
|
def before_request_phase(&block)
|
|
|
|
OmniAuth.config.before_request_phase = block
|
2013-02-25 18:52:36 -05:00
|
|
|
end
|
|
|
|
|
2013-09-03 11:16:18 -04:00
|
|
|
def before_callback_phase(&block)
|
|
|
|
OmniAuth.config.before_callback_phase = block
|
2013-02-25 18:52:36 -05:00
|
|
|
end
|
|
|
|
|
2011-09-03 14:08:07 -04:00
|
|
|
def configure(&block)
|
|
|
|
OmniAuth.configure(&block)
|
|
|
|
end
|
|
|
|
|
2012-04-12 17:01:48 -04:00
|
|
|
def options(options = false)
|
2019-11-11 01:33:08 -05:00
|
|
|
return @options ||= {} if options == false
|
2018-12-14 11:29:36 -05:00
|
|
|
|
2012-04-12 17:01:48 -04:00
|
|
|
@options = options
|
|
|
|
end
|
|
|
|
|
2022-04-13 12:52:45 -04:00
|
|
|
def provider(klass, *args, **opts, &block)
|
2011-09-03 14:08:07 -04:00
|
|
|
if klass.is_a?(Class)
|
|
|
|
middleware = klass
|
|
|
|
else
|
2011-11-25 09:03:23 -05:00
|
|
|
begin
|
2019-06-26 19:19:26 -04:00
|
|
|
middleware = OmniAuth::Strategies.const_get(OmniAuth::Utils.camelize(klass.to_s).to_s, false)
|
2011-11-25 09:03:23 -05:00
|
|
|
rescue NameError
|
2014-01-25 06:19:24 -05: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 09:03:23 -05:00
|
|
|
end
|
2011-09-03 14:08:07 -04:00
|
|
|
end
|
|
|
|
|
2022-04-13 12:52:45 -04:00
|
|
|
use middleware, *args, **options.merge(opts), &block
|
2011-09-03 14:08:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
|
|
|
to_app.call(env)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|