omniauth--omniauth/lib/omniauth/builder.rb

48 lines
1.1 KiB
Ruby
Raw Normal View History

2011-09-03 18:08:07 +00:00
module OmniAuth
class Builder < ::Rack::Builder
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
end
2013-09-03 15:16:18 +00:00
def before_request_phase(&block)
OmniAuth.config.before_request_phase = block
end
2013-09-03 15:16:18 +00:00
def before_callback_phase(&block)
OmniAuth.config.before_callback_phase = block
end
2011-09-03 18:08:07 +00:00
def configure(&block)
OmniAuth.configure(&block)
end
def options(options = false)
return @options ||= {} if options == false
@options = options
end
2022-04-13 16:52:45 +00:00
def provider(klass, *args, **opts, &block)
2011-09-03 18:08:07 +00:00
if klass.is_a?(Class)
middleware = klass
else
begin
middleware = OmniAuth::Strategies.const_get(OmniAuth::Utils.camelize(klass.to_s).to_s, false)
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})."))
end
2011-09-03 18:08:07 +00:00
end
2022-04-13 16:52:45 +00:00
use middleware, *args, **options.merge(opts), &block
2011-09-03 18:08:07 +00:00
end
def call(env)
to_app.call(env)
end
end
end