2011-09-22 14:25:41 -04:00
|
|
|
require 'omniauth'
|
2011-09-03 14:08:07 -04:00
|
|
|
|
|
|
|
module OmniAuth
|
|
|
|
class Builder < ::Rack::Builder
|
2012-01-17 15:57:54 -05:00
|
|
|
def initialize(app, &block)
|
|
|
|
if rack14?
|
|
|
|
super
|
|
|
|
else
|
|
|
|
@app = app
|
|
|
|
super(&block)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def rack14?
|
|
|
|
Rack.release.split('.')[1].to_i >= 4
|
|
|
|
end
|
|
|
|
|
2011-09-03 14:08:07 -04:00
|
|
|
def on_failure(&block)
|
|
|
|
OmniAuth.config.on_failure = block
|
|
|
|
end
|
|
|
|
|
|
|
|
def configure(&block)
|
|
|
|
OmniAuth.configure(&block)
|
|
|
|
end
|
|
|
|
|
|
|
|
def provider(klass, *args, &block)
|
|
|
|
if klass.is_a?(Class)
|
|
|
|
middleware = klass
|
|
|
|
else
|
2011-11-25 09:03:23 -05:00
|
|
|
begin
|
|
|
|
middleware = OmniAuth::Strategies.const_get("#{OmniAuth::Utils.camelize(klass.to_s)}")
|
|
|
|
rescue NameError
|
|
|
|
raise LoadError, "Could not find matching strategy for #{klass.inspect}. You may need to install an additional gem (such as omniauth-#{klass})."
|
|
|
|
end
|
2011-09-03 14:08:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
use middleware, *args, &block
|
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
2012-01-17 15:57:54 -05:00
|
|
|
@ins << @app unless rack14? || @ins.include?(@app)
|
2011-09-03 14:08:07 -04:00
|
|
|
to_app.call(env)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|