3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/omniauth_configure/rack.rb', line 3
def self.use_in(builder, configuration=nil, &block)
effective_configuration = configuration || OmniAuthConfigure.configuration
unless effective_configuration
fail "No configuration was provided. " <<
"Please set one or the other before calling use_in."
end
app = effective_configuration.app
klasses = effective_configuration.strategies
klasses.each do |klass|
if klass.is_a?(Class)
middleware = klass
else
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
end
p = effective_configuration.parameters_for(app, klass)
arg_keys = p.keys.sort
middleware.args arg_keys
args = p.values_at(*arg_keys)
args << {}
builder.use middleware, *args, &block
end
end
|