120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/j1_app/j1_auth_manager/warden_omniauth.rb', line 120
def call(env)
request = Rack::Request.new(env)
prefix = OmniAuth::Configuration.instance.path_prefix
if request.path =~ /^#{prefix}\/(.+?)\/callback$/i
strategy_name = Regexp.last_match(1)
strategy = Warden::Strategies._strategies.keys.detect { |k| k.to_s == "omni_#{strategy_name}" }
if !strategy
Rack::Response.new('Unknown Handler', 401).finish
else
session = env[SESSION_KEY]
scope = session[SCOPE_KEY]
if scope.nil? || scope.to_s.length < 100 args = [strategy]
args << { scope: scope.to_sym } if scope
response = Rack::Response.new
if env['warden'].authenticate? *args
response.redirect(redirect_after_callback_path)
response.finish
else
auth_path = request.path.gsub(/\/callback$/, '')
response.redirect(auth_path)
response.finish
end
else
Rack::Response.new('Bad Session', 400).finish
end
end
else
@app.call(env)
end
end
|