14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/atomic_lti_1v1/lti_1v1_middleware.rb', line 14
def call(env)
request = Rack::Request.new(env)
if matches_path_prefixes?(request) && AtomicLti1v1::Lti1v1.is_lti_1v1?(request)
oauth_consumer_key = request.params['oauth_consumer_key']
lti_secret = nil
begin
lti_secret = AtomicLti1v1.secret_provider.call(oauth_consumer_key)
rescue StandardError => e
Rails.logger.error("Error looking up lti secret, #{e}")
ensure
if lti_secret.blank?
Rails.logger.warn("No lti secret found for oauth_consumer_key: #{oauth_consumer_key}")
end
end
if lti_secret.present? && AtomicLti1v1::Lti1v1.valid_lti_request?(request, lti_secret)
env['atomic.validated.oauth_consumer_key'] = oauth_consumer_key
elsif lti_secret.present? && !AtomicLti1v1::Lti1v1.valid_lti_request?(request, lti_secret)
raise AtomicLti1v1::LtiValidationFailed, "Validation failed for oauth_consumer_key: #{oauth_consumer_key}"
end
env["atomic.validated.state_validation"] = {
state_verified: true,
}
end
@app.call(env)
end
|